unsigned LocalDateTime( sys_handle fh, int *time, int *date, int set ) /**************************************************************/ { struct _FILESTATUS fstatus; struct _FDATE *pdate; struct _FTIME *ptime; unsigned rc; pdate = (struct _FDATE *)date; ptime = (struct _FTIME *)time; if( set ) { rc = DosQFileInfo( fh, 1, (PBYTE)&fstatus, sizeof( fstatus ) ); if( rc != 0 ) return( StashErrCode( rc, OP_LOCAL ) ); fstatus.ftimeLastWrite = *ptime; fstatus.fdateLastWrite = *pdate; rc = DosSetFileInfo( fh, 1, (PBYTE)&fstatus, sizeof( fstatus ) ); if( rc != 0 ) return( StashErrCode( rc, OP_LOCAL ) ); } else { rc = DosQFileInfo( fh, 1, (PBYTE)&fstatus, sizeof( fstatus ) ); if( rc != 0 ) return( StashErrCode( rc, OP_LOCAL ) ); *ptime = fstatus.ftimeLastWrite; *pdate = fstatus.fdateLastWrite; } return( 0 ); }
_WCRTLINK int __F_NAME(utime,_wutime)( CHAR_TYPE const *fn, struct utimbuf const *times ) /***************************************************************************************/ { APIRET rc; OS_UINT actiontaken; FILESTATUS stat; HFILE handle; struct tm *split; time_t curr_time; struct utimbuf time_buf; #ifdef __WIDECHAR__ char mbPath[MB_CUR_MAX * _MAX_PATH]; /* single-byte char */ if( wcstombs( mbPath, fn, sizeof( mbPath ) ) == -1 ) { mbPath[0] = '\0'; } #endif rc = DosOpen( (PSZ)__F_NAME(fn,mbPath), &handle, &actiontaken, 0ul, _A_NORMAL, OPENFLAG_FAIL_IF_NOT_EXISTS | OPENFLAG_OPEN_IF_EXISTS, OPENMODE_DENY_NONE | OPENMODE_ACCESS_RDWR, 0ul ); if( rc != 0 ) { return( __set_errno_dos( rc ) ); } if( DosQFileInfo( handle, 1, (PBYTE)&stat, sizeof( FILESTATUS ) ) != 0 ) { DosClose( handle ); __set_errno( EACCES ); return( -1 ); } if( times == NULL ) { curr_time = time( NULL ); time_buf.modtime = curr_time; time_buf.actime = curr_time; times = &time_buf; } split = localtime( &(times->modtime) ); stat.fdateLastWrite.year = split->tm_year - 80; stat.fdateLastWrite.month = split->tm_mon + 1; stat.fdateLastWrite.day = split->tm_mday; stat.ftimeLastWrite.hours = split->tm_hour; stat.ftimeLastWrite.minutes = split->tm_min; stat.ftimeLastWrite.twosecs = split->tm_sec >> 1; /* 5-Apr-90 DJG * Early versions of OS/2 (1.10) do not support this fields properly. * We'll assume that if OS/2 returned a value here that we can set it * ourselves. Day has to be non-zero if the date is valid. */ if( stat.fdateLastAccess.day != 0 ) { split = localtime( &(times->actime) ); stat.fdateLastAccess.year = split->tm_year - 80; stat.fdateLastAccess.month = split->tm_mon + 1; stat.fdateLastAccess.day = split->tm_mday; stat.ftimeLastAccess.hours = split->tm_hour; stat.ftimeLastAccess.minutes = split->tm_min; stat.ftimeLastAccess.twosecs = split->tm_sec >> 1; }
_WCRTLINK int fstat( int handle, struct stat *buf ) #endif { APIRET error; OS_UINT hand_type; OS_UINT device_attr; FF_BUFFER info; unsigned iomode_flags; __handle_check( handle, -1 ); buf->st_mode = 0; iomode_flags = __GetIOMode( handle ); if( iomode_flags & _READ ) { buf->st_mode |= S_IRUSR | S_IRGRP | S_IROTH; } if( iomode_flags & _WRITE ) { buf->st_mode |= S_IWUSR | S_IWGRP | S_IWOTH; } error = DosQHandType( handle, &hand_type, &device_attr ); if( error ) { return( __set_errno_dos( error ) ); } if( ( hand_type & ~HANDTYPE_NETWORK ) == HANDTYPE_FILE ) { /* handle file */ error = DosQFileInfo( handle, FF_LEVEL, (PBYTE)&info, sizeof( info ) ); if( error ) { return( __set_errno_dos( error ) ); } buf->st_dev = buf->st_rdev = 0; /* handle timestamps */ buf->st_ctime = _d2ttime( TODDATE( info.fdateCreation ), TODTIME( info.ftimeCreation ) ); buf->st_atime = _d2ttime( TODDATE( info.fdateLastAccess ), TODTIME( info.ftimeLastAccess ) ); buf->st_mtime = _d2ttime( TODDATE( info.fdateLastWrite ), TODTIME( info.ftimeLastWrite ) ); buf->st_btime = buf->st_mtime; #if defined( __INT64__ ) && !defined( _M_I86 ) if( _FILEAPI64() ) { #endif buf->st_attr = info.attrFile; buf->st_mode |= at2mode( info.attrFile ); buf->st_size = info.cbFile; #if defined( __INT64__ ) && !defined( _M_I86 ) } else { buf->st_attr = ((FF_BUFFER_32 *)&info)->attrFile; buf->st_mode |= at2mode( ((FF_BUFFER_32 *)&info)->attrFile ); buf->st_size = ((FF_BUFFER_32 *)&info)->cbFile; } #endif } else { /* handle device */ /* handle attributes */ buf->st_attr = 0; buf->st_mode |= S_IRUSR | S_IRGRP | S_IROTH; if( ( hand_type & ~HANDTYPE_NETWORK ) == HANDTYPE_DEVICE ) { buf->st_mode |= S_IFCHR; } else if( ( hand_type & ~HANDTYPE_NETWORK ) == HANDTYPE_PIPE ) { buf->st_mode |= S_IFIFO; } buf->st_dev = buf->st_rdev = 1; /* handle timestamps */ buf->st_atime = 0; buf->st_ctime = 0; buf->st_mtime = 0; buf->st_btime = 0; /* handle size */ buf->st_size = 0; } buf->st_nlink = 1; buf->st_ino = handle; buf->st_uid = buf->st_gid = 0; buf->st_archivedID = 0; buf->st_updatedID = 0; buf->st_inheritedRightsMask = 0; buf->st_originatingNameSpace = 0; return( 0 ); }
long LocalGetFreeSpace( int drv ) /*******************************/ { struct _FSALLOCATE usage; #ifdef _M_I86 if( DosQFSInfo( drv, 1, (PBYTE)&usage, sizeof( usage ) ) ) { #else if( DosQueryFSInfo( drv, 1, (PBYTE)&usage, sizeof( usage ) ) ) { #endif return( -1L ); } return( usage.cbSector * usage.cSectorUnit * usage.cUnitAvail ); } error_handle LocalDateTime( sys_handle fh, int *time, int *date, int set ) /************************************************************************/ { struct _FILESTATUS fstatus; struct _FDATE *pdate; struct _FTIME *ptime; unsigned rc; pdate = (struct _FDATE *)date; ptime = (struct _FTIME *)time; if( set ) { #ifdef _M_I86 rc = DosQFileInfo( fh, 1, (PBYTE)&fstatus, sizeof( fstatus ) ); #else rc = DosQueryFileInfo( fh, FIL_STANDARD, (PBYTE)&fstatus, sizeof( fstatus ) ); #endif if( rc != 0 ) return( StashErrCode( rc, OP_LOCAL ) ); fstatus.ftimeLastWrite = *ptime; fstatus.fdateLastWrite = *pdate; rc = DosSetFileInfo( fh, 1, (PBYTE)&fstatus, sizeof( fstatus ) ); if( rc != 0 ) { return( StashErrCode( rc, OP_LOCAL ) ); } } else { #ifdef _M_I86 rc = DosQFileInfo( fh, 1, (PBYTE)&fstatus, sizeof( fstatus ) ); #else rc = DosQueryFileInfo( fh, FIL_STANDARD, (PBYTE)&fstatus, sizeof( fstatus ) ); #endif if( rc != 0 ) return( StashErrCode( rc, OP_LOCAL ) ); *ptime = fstatus.ftimeLastWrite; *pdate = fstatus.fdateLastWrite; } return( 0 ); } error_handle LocalGetCwd( int drive, char *where ) /************************************************/ { APIRET len; len = 256; #ifdef _M_I86 return( StashErrCode( DosQCurDir( drive, (PBYTE)where, &len ), OP_LOCAL ) ); #else return( StashErrCode( DosQueryCurrentDir( drive, (PBYTE)where, &len ), OP_LOCAL ) ); #endif }