pike.git / src / modules / _Stdio / efuns.c

version» Context lines:

pike.git/src/modules/_Stdio/efuns.c:439:      /*! @decl int file_truncate(string file, int length)    *!    *! Truncates the file @[file] to the length specified in @[length].    *!    *! @returns    *! Returns 1 if ok, 0 if failed.    */   void f_file_truncate(INT32 args)   { - #if defined(INT64) +     INT64 len = 0; - #else -  off_t len = 0; - #endif +     struct pike_string *str;    int res;       if(args != 2)    SIMPLE_WRONG_NUM_ARGS_ERROR("file_truncate", 2);    if(TYPEOF(sp[-args]) != T_STRING)    SIMPLE_ARG_TYPE_ERROR("file_truncate", 1, "string");    - #if defined (INT64) +    #if defined (HAVE_FTRUNCATE64) || SIZEOF_OFF_T > SIZEOF_INT_TYPE    if(is_bignum_object_in_svalue(&Pike_sp[1-args])) {    if (!int64_from_bignum(&len, Pike_sp[1-args].u.object))    Pike_error ("Bad argument 2 to file_truncate(). Length too large.\n");    }    else   #endif - #endif +     if(TYPEOF(sp[1-args]) != T_INT)    SIMPLE_ARG_TYPE_ERROR("file_truncate", 2, "int");    else    len = sp[1-args].u.integer;       str = sp[-args].u.string;       if (string_has_null(str)) {    /* Filenames with NUL are not supported. */    errno = ENOENT;
pike.git/src/modules/_Stdio/efuns.c:487: Inside #if defined(__NT__)
   {    HANDLE h = CreateFile(str->str, GENERIC_WRITE,    FILE_SHARE_READ|FILE_SHARE_WRITE,    NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);    if(h == INVALID_HANDLE_VALUE) {    errno = GetLastError();    res=-1;    } else {    LONG high;    DWORD err; - #ifdef INT64 +     high = (LONG) (len >> 32);    len &= ((INT64) 1 << 32) - 1; - #else -  high = 0; - #endif +     if (SetFilePointer(h, (LONG) len, &high, FILE_BEGIN) ==    INVALID_SET_FILE_POINTER &&    (err = GetLastError()) != NO_ERROR) {    errno = err;    res = -1;    }    else if (!SetEndOfFile(h)) {    errno = GetLastError();    res=-1;    }