Ignore:
Timestamp:
Sep 25, 2019, 12:43:50 AM (6 years ago)
Author:
Alex Taylor
Message:

Add Sys2SetSize

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rxutilex/trunk/rxutilex.c

    r47 r48  
    11/******************************************************************************
    22 * REXX Utility Functions - Extended (RXUTILEX.DLL)                           *
    3  * (C) 2011, 2017 Alex Taylor.                                                *
     3 * (C) 2011, 2019 Alex Taylor.                                                *
    44 *                                                                            *
    55 * LICENSE:                                                                   *
     
    147147    "Sys2Close",
    148148    "Sys2Seek",
     149    "Sys2SetSize",
    149150    "Sys2BytesRemaining",
    150151    "Sys2Read",
     
    196197RexxFunctionHandler Sys2Write;
    197198RexxFunctionHandler Sys2SyncBuffer;
     199RexxFunctionHandler Sys2SetSize;
    198200
    199201
     
    202204
    203205#ifndef LEGACY_C_LOCALE
    204 int GetLocaleString( PSZ *ppszItem, LocaleItem item );
     206    int GetLocaleString( PSZ *ppszItem, LocaleItem item );
    205207    void GroupNumber( PSZ buf, ULONGLONG val, PSZ sep );
    206208#endif
     
    22082210    sprintf( achActual, "%lld", llActual );
    22092211    SaveResultString( prsResult, achActual, strlen(achActual) );        // 2016-02-20 SHL
     2212
     2213    return ( 0 );
     2214}
     2215
     2216
     2217/* ------------------------------------------------------------------------- *
     2218 * Sys2SetSize                                                               *
     2219 *                                                                           *
     2220 * Wrapper to DosSetFileSizeL: set the size of a file opened with Sys2Open.  *
     2221 *                                                                           *
     2222 * REXX ARGUMENTS:                                                           *
     2223 *   1. File handle (returned by Sys2Open)                        (REQUIRED) *
     2224 *   2. The new size of the file                                  (REQUIRED) *
     2225 *                                                                           *
     2226 * REXX RETURN VALUE:                                                        *
     2227 *   1 on success, or 0 if an error occurred.                                *
     2228 * ------------------------------------------------------------------------- */
     2229ULONG APIENTRY Sys2SetSize( PSZ pszName, ULONG argc, RXSTRING argv[], PSZ pszQueue, PRXSTRING prsResult )
     2230{
     2231    HFILE    hf;
     2232    LONGLONG llSize;
     2233    APIRET   rc;
     2234
     2235    // Reset the error indicator
     2236    WriteErrorCode( 0, NULL );
     2237
     2238    // Make sure we have two valid arguments
     2239    if ( argc < 2 || ( !RXVALIDSTRING(argv[0]) ) || ( !RXVALIDSTRING(argv[1]) ))
     2240        return ( 40 );
     2241
     2242    // First argument: file handle
     2243    if (( sscanf( argv[0].strptr, "%8X", &hf )) != 1 ) return ( 40 );
     2244
     2245    // Second argument: requested size
     2246    if (( sscanf( argv[1].strptr, "%lld", &llSize )) != 1 ) return ( 40 );
     2247
     2248    rc = DosSetFileSizeL( hf, llSize );
     2249    if ( rc != NO_ERROR ) {
     2250        WriteErrorCode( rc, "DosSetFileSizeL");
     2251        SaveResultString( prsResult, PSZ_ZERO, 1 );
     2252    }
     2253    else {
     2254        SaveResultString( prsResult, PSZ_ONE, 1 );
     2255    }
    22102256
    22112257    return ( 0 );
Note: See TracChangeset for help on using the changeset viewer.