sqInt dir_EntryLookup(char *pathString, sqInt pathStringLength, char* nameString, sqInt nameStringLength, /* outputs: */ char *name, sqInt *nameLength, sqInt *creationDate, sqInt *modificationDate, sqInt *isDirectory, squeakFileOffsetType *sizeIfFile, sqInt *posixPermissions, sqInt *isSymlink) { /* Lookup the given name in the given directory, Set the name, name length, creation date, creation time, directory flag, and file size (if the entry is a file). Return: 0 if a entry is found at the given index 1 if there is no such entry in the directory 2 if the given path has bad syntax or does not reach a directory */ char unixPath[MAXPATHLEN+1]; struct stat statBuf; /* default return values */ *name = 0; *nameLength = 0; *creationDate = 0; *modificationDate = 0; *isDirectory = false; *sizeIfFile = 0; *posixPermissions = 0; *isSymlink = false; if ((pathStringLength == 0)) strcpy(unixPath, "."); else if (!sq2uxPath(pathString, pathStringLength, unixPath, MAXPATHLEN, 1)) return BAD_PATH; char terminatedName[MAXPATHLEN+1]; strncpy(terminatedName, nameString, nameStringLength); terminatedName[nameStringLength]= '\0'; strcat(unixPath, "/"); strcat(unixPath, terminatedName); if (stat(unixPath, &statBuf) && lstat(unixPath, &statBuf)) { return NO_MORE_ENTRIES; } /* To match the results of dir_Lookup, copy back the file name */ *nameLength = ux2sqPath(nameString, nameStringLength, name, 256, 0); /* last change time */ *creationDate= convertToSqueakTime(statBuf.st_ctime); /* modification time */ *modificationDate= convertToSqueakTime(statBuf.st_mtime); if (S_ISDIR(statBuf.st_mode)) *isDirectory= true; else *sizeIfFile= statBuf.st_size; *isSymlink = S_ISLNK(statBuf.st_mode); *posixPermissions = statBuf.st_mode & 0777; return ENTRY_FOUND; }
int dir_Lookup(char *pathString, int pathStringLength, int index, /* outputs: */ char *name, int *nameLength, int *creationDate, int *modificationDate, int *isDirectory, squeakFileOffsetType *sizeIfFile) { /* Lookup the index-th entry of the directory with the given path, starting at the root of the file system. Set the name, name length, creation date, creation time, directory flag, and file size (if the entry is a file). Return: 0 if a entry is found at the given index 1 if the directory has fewer than index entries 2 if the given path has bad syntax or does not reach a directory */ int okay; HVolumeParam volumeParams; FSSpec spec; long parentDirectory; OSErr err; Str255 longFileName; /* default return values */ *name = 0; *nameLength = 0; *creationDate = 0; *modificationDate = 0; *isDirectory = false; *sizeIfFile = 0; if ((pathStringLength == 0)) { /* get volume info */ volumeParams.ioNamePtr = (unsigned char *) name; volumeParams.ioVRefNum = 0; volumeParams.ioVolIndex = index; okay = PBHGetVInfoSync((HParmBlkPtr) &volumeParams) == noErr; if (okay) { CopyPascalStringToC((ConstStr255Param) name,name); *nameLength = strlen(name); *creationDate = convertToSqueakTime(volumeParams.ioVCrDate); *modificationDate = convertToSqueakTime(volumeParams.ioVLsMod); *isDirectory = true; *sizeIfFile = 0; return ENTRY_FOUND; } else { return NO_MORE_ENTRIES; } } else { /* get file or directory info */ if (!equalsLastPath(pathString, pathStringLength)) { /* lookup and cache the refNum for this path */ err = lookupPath(pathString, pathStringLength, &spec,false,true); if (err == noErr) recordPath(pathString, pathStringLength, &spec); else return BAD_PATH; } spec = lastSpec; *sizeIfFile = 0; okay = fetchFileInfo(index,&spec,(unsigned char *) name,true,&parentDirectory,isDirectory,creationDate,modificationDate,sizeIfFile,&longFileName); if (okay == noErr) { CopyPascalStringToC((ConstStr255Param) longFileName,name); *nameLength = strlen(name); *creationDate = convertToSqueakTime(*creationDate); *modificationDate = convertToSqueakTime(*modificationDate); return ENTRY_FOUND; } else return okay == fnfErr ? NO_MORE_ENTRIES : BAD_PATH; } }
int dir_Lookup(char *pathString, int pathStringLength, int index, /* outputs: */ char *name, int *nameLength, int *creationDate, int *modificationDate, int *isDirectory, squeakFileOffsetType *sizeIfFile) { /* Lookup the index-th entry of the directory with the given path, starting at the root of the file system. Set the name, name length, creation date, creation time, directory flag, and file size (if the entry is a file). Return: 0 if a entry is found at the given index 1 if the directory has fewer than index entries 2 if the given path has bad syntax or does not reach a directory */ int okay; FSSpec spec; long parentDirectory; OSErr err; Str255 longFileName; FSVolumeInfoParam fsVolumeParam; HFSUniStr255 uniStr; FSVolumeInfo volumeInfo; /* default return values */ *name = 0; *nameLength = 0; *creationDate = 0; *modificationDate = 0; *isDirectory = false; *sizeIfFile = 0; if ((pathStringLength == 0)) { /* get volume info */ fsVolumeParam.volumeName = &uniStr; fsVolumeParam.ioVRefNum = kFSInvalidVolumeRefNum; fsVolumeParam.volumeIndex = index; fsVolumeParam.whichInfo = 0; fsVolumeParam.volumeInfo = &volumeInfo; fsVolumeParam.ref = NULL; fsVolumeParam.whichInfo = kFSVolInfoCreateDate + kFSVolInfoModDate; okay = PBGetVolumeInfoSync( &fsVolumeParam) == noErr; /* FSGetVolumeInfo (kFSInvalidVolumeRefNum, index, NULL, ) */ if (okay) { CFStringRef strRef = CFStringCreateWithCharacters( kCFAllocatorDefault, uniStr.unicode, uniStr.length ); CFMutableStringRef mStr = CFStringCreateMutableCopy(NULL, 0, strRef); // HFS+ imposes Unicode2.1 decomposed UTF-8 encoding on all path elements if (gCurrentVMEncoding == kCFStringEncodingUTF8) CFStringNormalize(mStr, kCFStringNormalizationFormKC); // pre-combined Boolean result = CFStringGetCString(mStr, name, 256, gCurrentVMEncoding); // buffer size is to see primitiveDirectoryLookup CFRelease(strRef); CFRelease(mStr); if (result == true) { // strncpy(name, &(uniStr.unicode), uniStr.length); // *nameLength = uniStr.length; *nameLength = strlen(name); { LocalDateTime local; ConvertUTCToLocalDateTime(&fsVolumeParam.volumeInfo->createDate,&local); *creationDate = convertToSqueakTime(local.lowSeconds); } { LocalDateTime local; ConvertUTCToLocalDateTime(&fsVolumeParam.volumeInfo->modifyDate,&local); *modificationDate = convertToSqueakTime(local.lowSeconds); } *isDirectory = true; *sizeIfFile = 0; return ENTRY_FOUND; } else { return NO_MORE_ENTRIES; } } else { return NO_MORE_ENTRIES; } } else { /* get file or directory info */ if (!equalsLastPath(pathString, pathStringLength)) { /* lookup and cache the refNum for this path */ err = lookupPath(pathString, pathStringLength, &spec,false,true); if (err == noErr) recordPath(pathString, pathStringLength, &spec); else return BAD_PATH; } spec = lastSpec; *sizeIfFile = 0; okay = fetchFileInfo(index,&spec,(unsigned char *) name,true, &parentDirectory,isDirectory,creationDate, modificationDate,sizeIfFile,&longFileName); if (okay == noErr) { CFStringRef cfs= CFStringCreateWithPascalString(NULL, longFileName, gCurrentVMEncoding); CFMutableStringRef mStr= CFStringCreateMutableCopy(NULL, 0, cfs); CFRelease(cfs); // HFS+ imposes Unicode2.1 decomposed UTF-8 encoding on all path elements if (gCurrentVMEncoding == kCFStringEncodingUTF8) CFStringNormalize(mStr, kCFStringNormalizationFormKC); // pre-combined CFStringGetCString(mStr, name, 256, gCurrentVMEncoding); CFRelease(mStr); *nameLength = strlen(name); *creationDate = convertToSqueakTime(*creationDate); *modificationDate = convertToSqueakTime(*modificationDate); return ENTRY_FOUND; } else return okay == fnfErr ? NO_MORE_ENTRIES : BAD_PATH; } }
/* Lookup the index-th entry of the directory with the given path, starting at the root of the file system. Set the name, name length, creation date, creation time, directory flag, and file size (if the entry is a file). Return: 0 if a entry is found at the given index 1 if the directory has fewer than index entries 2 if the given path has bad syntax or does not reach a directory */ int dir_Lookup(char *pathString, int pathStringLength, int index /* starting at 1 */, // outputs: char *name, int *nameLength, int *creationDate, int *modificationDate, int *isDirectory, squeakFileOffsetType *sizeIfFile) { /* default return values */ *name = 0; *nameLength = 0; *creationDate = 0; *modificationDate = 0; *isDirectory = false; *sizeIfFile = 0; // copy the file name into a null-terminated C string char cPathName[1001]; if (sizeof cPathName <= pathStringLength) { return BAD_PATH; } sqFilenameFromString(cPathName, pathString, pathStringLength); /* get file or directory info */ int i; Handle<es::Iterator> iter(gRoot->list(cPathName)); if (!iter) { return BAD_PATH; } for (i = 1; iter->hasNext(); ++i) { Handle<es::Binding> binding(iter->next()); if (i == index) { binding->getName(name, MAX_PATH); *nameLength = strlen(name); Handle<es::File> file(binding); if (file) { long long tick; tick = file->getCreationTime(); *creationDate = convertToSqueakTime(tick); tick = file->getLastWriteTime(); *modificationDate = convertToSqueakTime(tick); } Handle<es::Context> context(binding); if (context) { *isDirectory = true; *sizeIfFile = 0; } else { Handle<es::Stream> stream(file->getStream()); // XXX Check exception if (stream) { *isDirectory = false; long long size; size = stream->getSize(); *sizeIfFile = size; } else { ++index; continue; } } return ENTRY_FOUND; } } return NO_MORE_ENTRIES; }
/* returns the local wall clock time */ int ioSeconds(void) { SYSTEMTIME sysTime; GetLocalTime(&sysTime); return convertToSqueakTime(sysTime); }
sqInt dir_Lookup(char *pathString, sqInt pathStringLength, sqInt index, /* outputs: */ char *name, sqInt *nameLength, sqInt *creationDate, sqInt *modificationDate, sqInt *isDirectory, squeakFileOffsetType *sizeIfFile) #endif { /* Lookup the index-th entry of the directory with the given path, starting at the root of the file system. Set the name, name length, creation date, creation time, directory flag, and file size (if the entry is a file). Return: 0 if a entry is found at the given index 1 if the directory has fewer than index entries 2 if the given path has bad syntax or does not reach a directory */ int i; int nameLen= 0; struct dirent *dirEntry= 0; char unixPath[MAXPATHLEN+1]; struct stat statBuf; /* default return values */ *name = 0; *nameLength = 0; *creationDate = 0; *modificationDate = 0; *isDirectory = false; *sizeIfFile = 0; #if PharoVM *posixPermissions = 0; *isSymlink = false; #endif if ((pathStringLength == 0)) strcpy(unixPath, "."); else if (!sq2uxPath(pathString, pathStringLength, unixPath, MAXPATHLEN, 1)) return BAD_PATH; /* get file or directory info */ if (!maybeOpenDir(unixPath)) return BAD_PATH; if (++lastIndex == index) index= 1; /* fake that the dir is rewound and we want the first entry */ else { rewinddir(openDir); /* really rewind it, and read to the index */ lastIndex= index; } for (i= 0; i < index; i++) { nextEntry: do { errno= 0; dirEntry= readdir(openDir); } while ((dirEntry == 0) && (errno == EINTR)); if (!dirEntry) return NO_MORE_ENTRIES; nameLen= NAMLEN(dirEntry); /* ignore '.' and '..' (these are not *guaranteed* to be first) */ if (nameLen < 3 && dirEntry->d_name[0] == '.') if (nameLen == 1 || dirEntry->d_name[1] == '.') goto nextEntry; } *nameLength= ux2sqPath(dirEntry->d_name, nameLen, name, MAXPATHLEN, 0); { char terminatedName[MAXPATHLEN+1]; if(nameLen > MAXPATHLEN) return BAD_PATH; strncpy(terminatedName, dirEntry->d_name, nameLen); terminatedName[nameLen]= '\0'; if(strlen(unixPath) + 1 + nameLen > MAXPATHLEN) return BAD_PATH; strcat(unixPath, "/"); strcat(unixPath, terminatedName); if (stat(unixPath, &statBuf) && lstat(unixPath, &statBuf)) { /* We can't stat the entry, but failing here would invalidate the whole directory --bertf */ return ENTRY_FOUND; } } /* last change time */ *creationDate= convertToSqueakTime(statBuf.st_ctime); /* modification time */ *modificationDate= convertToSqueakTime(statBuf.st_mtime); if (S_ISDIR(statBuf.st_mode)) *isDirectory= true; else *sizeIfFile= statBuf.st_size; #if PharoVM *isSymlink = S_ISLNK(statBuf.st_mode); *posixPermissions = statBuf.st_mode & 0777; #endif return ENTRY_FOUND; }
/* returns the local wall clock time */ sqInt ioSeconds(void) { return convertToSqueakTime(time(0)); }
sqInt ioSeconds(void) { return (sqInt)convertToSqueakTime(time(NULL)); }
sqInt dir_Lookup(char *pathString, sqInt pathStringLength, sqInt index, /* outputs: */ char *name, sqInt *nameLength, sqInt *creationDate, sqInt *modificationDate, sqInt *isDirectory, squeakFileOffsetType *sizeIfFile) { /* Lookup the index-th entry of the directory with the given path, starting at the root of the file system. Set the name, name length, creation date, creation time, directory flag, and file size (if the entry is a file). Return: 0 if a entry is found at the given index 1 if the directory has fewer than index entries 2 if the given path has bad syntax or does not reach a directory */ int i; int nameLen= 0; struct dirent *dirEntry= 0; char unixPath[DOCUMENT_NAME_SIZE+1]; struct stat statBuf; /* default return values */ *name = 0; *nameLength = 0; *creationDate = 0; *modificationDate = 0; *isDirectory = false; *sizeIfFile = 0; if ((pathStringLength == 0)) strcpy(unixPath, "."); else { if (!ioFilenamefromStringofLengthresolveAliasesRetry(unixPath, pathString,pathStringLength, true, true)) return BAD_PATH; } /* get file or directory info */ if (!maybeOpenDir(unixPath)) return BAD_PATH; if (++lastIndex == index) index= 1; /* fake that the dir is rewound and we want the first entry */ else { rewinddir(openDir); /* really rewind it, and read to the index */ lastIndex= index; } for (i= 0; i < index; i++) { nextEntry: do { errno= 0; dirEntry= readdir(openDir); } while ((dirEntry == 0) && (errno == EINTR)); if (!dirEntry) return NO_MORE_ENTRIES; nameLen= NAMLEN(dirEntry); /* ignore '.' and '..' (these are not *guaranteed* to be first) */ if (nameLen < 3 && dirEntry->d_name[0] == '.') if (nameLen == 1 || dirEntry->d_name[1] == '.') goto nextEntry; } *nameLength= ux2sqPath(dirEntry->d_name, nameLen, name, 256, 0); { char terminatedName[DOCUMENT_NAME_SIZE+1]; strncpy(terminatedName, dirEntry->d_name, nameLen); terminatedName[nameLen]= '\0'; strcat(unixPath, "/"); strcat(unixPath, terminatedName); if (stat(unixPath, &statBuf) && lstat(unixPath, &statBuf)) { /* We can't stat the entry, but failing here would invalidate the whole directory --bertf */ return ENTRY_FOUND; } } /* last change time */ *creationDate= convertToSqueakTime(statBuf.st_ctime); /* modification time */ *modificationDate= convertToSqueakTime(statBuf.st_mtime); { FSRef targetFSRef; Boolean targetIsFolder,wasAliased; OSErr err; err = getFSRef(unixPath,&targetFSRef,kCFStringEncodingUTF8); if (!err) { FSResolveAliasFileWithMountFlags(&targetFSRef,true,&targetIsFolder,&wasAliased,kResolveAliasFileNoUI); if (wasAliased && targetIsFolder) { *isDirectory= true; return ENTRY_FOUND; } } } if (S_ISDIR(statBuf.st_mode)) *isDirectory= true; else *sizeIfFile= statBuf.st_size; return ENTRY_FOUND; }