static void MakeStat(TFileStat& st, const TSystemFStat& fs) { #ifdef _unix_ st.Mode = fs.st_mode; st.NLinks = fs.st_nlink; st.Uid = fs.st_uid; st.Gid = fs.st_gid; st.Size = fs.st_size; st.ATime = fs.st_atime; st.MTime = fs.st_mtime; st.CTime = fs.st_ctime; #else timeval tv; FileTimeToTimeval(&fs.ftCreationTime, &tv); st.CTime = tv.tv_sec; FileTimeToTimeval(&fs.ftLastAccessTime, &tv); st.ATime = tv.tv_sec; FileTimeToTimeval(&fs.ftLastWriteTime, &tv); st.MTime = tv.tv_sec; st.NLinks = fs.nNumberOfLinks; st.Mode = GetFileMode(fs.dwFileAttributes); st.Uid = 0; st.Gid = 0; st.Size = ((ui64)fs.nFileSizeHigh << 32) | fs.nFileSizeLow; #endif }
bool File::Exists(StringRef filePath, int permission) { /* mode Value Checks File For 00 Existence only 02 Write permission 04 Read permission 06 Read and write permission */ FileMode outFileMode; if (GetFileMode(filePath, outFileMode)) { if (outFileMode == FileMode::File) { return true; } } return false; //#ifdef MEDUSA_WINDOWS // return _access(filePath.Buffer(),permission)!=-1; //#else // return access(filePath.Buffer(),permission)!=-1; // //#endif }
/* =========================================================================== * If file *f does not exist, return 0. Else, return the file's last * modified date and time as an MSDOS date and time. The date and * time is returned in a long with the date most significant to allow * unsigned integer comparison of absolute times. Also, if a is not * a NULL pointer, store the file attributes there, with the high two * bytes being the Unix attributes, and the low byte being a mapping * of that to DOS attributes. If n is not NULL, store the file size * there. If t is not NULL, the file's access and modification time * are stored there as UNIX time_t values. * If f is "-", use standard input as the file. If f is a device, return * a file size of -1 *f :: Name of file to get info on. *a :: Return value: file attributes. *n :: Return value: file size. *t :: Return value: access and modification time. */ ulg filetime( char *f, ulg *a, long *n, ztimbuf *t, struct Globals *pG ) { struct stat s; /* results of stat() */ char name[FNMAX]; int len = lstrlen( f ), isstdin = !strcmp( f, "-" ); if ( f == pG->label ) { if ( a != NULL ) *a = pG->label_mode; if ( n != NULL ) *n = -2L; /* convention for a label name */ if ( t != NULL ) t->actime = t->modtime = pG->label_utim; return pG->label_time; } lstrcpy( name, f ); /* not all systems allow stat'ing a file with / appended, so remove it */ if ( name[len - 1] == '\\' ) name[len - 1] = '\0'; // SLASH /* Accept about any kind of file including directories */ if ( LSSTAT( GetFullPath( pG, name ), &s ) != 0 ) return 0; // error in stat! if ( a != NULL ) { *a = ( (ulg)s.st_mode << 16) | (isstdin ? 0L : (ulg)GetFileMode( pG, name ) ); } if ( n != NULL ) *n = (s.st_mode & S_IFMT) == S_IFREG ? s.st_size : -1L; if ( t != NULL ) { t->actime = s.st_atime; t->modtime = s.st_mtime; } return unix2dostime( (time_t *)&s.st_mtime ); }
void * IOR_Create_NCMPI(char * testFileName, IOR_param_t * param) { int * fd; int fd_mode; MPI_Info mpiHints = MPI_INFO_NULL; /* Wei-keng Liao: read and set MPI file hints from hintsFile */ SetHints(&mpiHints, param->hintsFileName); if (rank == 0 && param->showHints) { fprintf(stdout, "\nhints passed to MPI_File_open() {\n"); ShowHints(&mpiHints); fprintf(stdout, "}\n"); } fd = (int *)malloc(sizeof(int)); if (fd == NULL) ERR("Unable to malloc file descriptor"); fd_mode = GetFileMode(param); NCMPI_CHECK(ncmpi_create(testComm, testFileName, fd_mode, mpiHints, fd), "cannot create file"); /* Wei-keng Liao: print the MPI file hints currently used */ /* WEL - add when ncmpi_get_file_info() is in current parallel-netcdf release if (rank == 0 && param->showHints) { MPI_CHECK(ncmpi_get_file_info(*fd, &mpiHints), "cannot get file info"); fprintf(stdout, "\nhints returned from opened file {\n"); ShowHints(&mpiHints); fprintf(stdout, "}\n"); } */ /* Wei-keng Liao: free up the mpiHints object */ /* WEL - this needs future fix from next release of PnetCDF if (mpiHints != MPI_INFO_NULL) MPI_CHECK(MPI_Info_free(&mpiHints), "cannot free file info"); */ return(fd); } /* IOR_Create_NCMPI() */
const string CMsgQueue::MsgStat(int aMsgId) { int ret = RET_ERROR; struct msqid_ds queueStat; memset(&queueStat, 0, sizeof(queueStat)); do { ret = msgctl(aMsgId, IPC_STAT, &queueStat); } while (ret == RET_ERROR && errno == EINTR); if (ret == RET_OK) { char statBuf[100] = {0}; char modeBuf[10] = {0}; snprintf(statBuf, sizeof(statBuf), "TYPE:q; KEY:%x; MODE:%s; OWNER:%d; GROUP:%d; " "CBYTES:%d; QNUM:%d; QBYTES:%d.", aMsgId, GetFileMode(queueStat.msg_perm.mode, modeBuf), queueStat.msg_perm.uid, queueStat.msg_perm.gid, queueStat.msg_cbytes, queueStat.msg_qnum, queueStat.msg_qbytes); return statBuf; } return string(" "); }