Miscellaneous fixes
This commit is contained in:
@@ -59,7 +59,7 @@ FileTime FileTime_Get(char *fileName) {
|
||||
HANDLE hFile;
|
||||
FILETIME ftCreate, ftAccess, ftWrite;
|
||||
hFile = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ, NULL,
|
||||
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL );
|
||||
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
||||
GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite);
|
||||
CloseHandle(hFile);
|
||||
return (FileTime_to_POSIX(ftWrite));
|
||||
@@ -69,7 +69,7 @@ void FileTime_Set(char *fileName, FileTime fileTime) {
|
||||
HANDLE hFile;
|
||||
FILETIME ftWrite;
|
||||
hFile = CreateFile(fileName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
|
||||
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL );
|
||||
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
||||
ftWrite = POSIX_to_FileTime(fileTime);
|
||||
SetFileTime(hFile, NULL, NULL, &ftWrite);
|
||||
CloseHandle(hFile);
|
||||
@@ -96,10 +96,10 @@ void FileTime_Set(char *fileName, FileTime t) {
|
||||
void FileTime_Print(FileTime fileTime) {
|
||||
struct tm *tms;
|
||||
|
||||
tms = localtime((time_t *) &fileTime);
|
||||
tms = localtime((time_t *)&fileTime);
|
||||
printff("%04d-%02d-%02d %02d:%02d:%02d", tms->tm_year + 1900,
|
||||
tms->tm_mon + 1, tms->tm_mday, tms->tm_hour, tms->tm_min,
|
||||
tms->tm_sec);
|
||||
tms->tm_mon + 1, tms->tm_mday, tms->tm_hour, tms->tm_min,
|
||||
tms->tm_sec);
|
||||
}
|
||||
|
||||
void File_GetName(char *path, char *name) {
|
||||
@@ -110,7 +110,8 @@ void File_GetName(char *path, char *name) {
|
||||
if (path[i] == '/' || path[i] == '\\') {
|
||||
i++;
|
||||
break;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
i--;
|
||||
}
|
||||
}
|
||||
@@ -132,7 +133,7 @@ int File_ExistsPath(char *path) {
|
||||
unsigned rc;
|
||||
rc = GetFileAttributes(path);
|
||||
|
||||
if (rc == INVALID_FILE_ATTRIBUTES ) {
|
||||
if (rc == INVALID_FILE_ATTRIBUTES) {
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
@@ -141,7 +142,7 @@ int File_IsDirectory(char *fileName) {
|
||||
unsigned rc;
|
||||
rc = GetFileAttributes(fileName);
|
||||
|
||||
if (rc == INVALID_FILE_ATTRIBUTES ) {
|
||||
if (rc == INVALID_FILE_ATTRIBUTES) {
|
||||
return (0);
|
||||
}
|
||||
if (rc & FILE_ATTRIBUTE_DIRECTORY) {
|
||||
@@ -153,7 +154,7 @@ int File_IsFile(char *fileName) {
|
||||
unsigned rc;
|
||||
rc = GetFileAttributes(fileName);
|
||||
|
||||
if (rc == INVALID_FILE_ATTRIBUTES ) {
|
||||
if (rc == INVALID_FILE_ATTRIBUTES) {
|
||||
return (0);
|
||||
}
|
||||
if (rc & FILE_ATTRIBUTE_DIRECTORY) {
|
||||
@@ -201,7 +202,7 @@ long long File_GetSize(char *fileName) {
|
||||
HANDLE hFile;
|
||||
DWORD fSize;
|
||||
hFile = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ, NULL,
|
||||
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL );
|
||||
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
||||
GetFileSize(hFile, &fSize);
|
||||
CloseHandle(hFile);
|
||||
return (fSize);
|
||||
@@ -221,7 +222,7 @@ void File_GetSizeAndTime(char *fileName, long long *size, FileTime *time) {
|
||||
DWORD fSize;
|
||||
FILETIME ftCreate, ftAccess, ftWrite;
|
||||
hFile = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ, NULL,
|
||||
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL );
|
||||
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
||||
GetFileSize(hFile, &fSize);
|
||||
GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite);
|
||||
CloseHandle(hFile);
|
||||
@@ -253,7 +254,7 @@ int File_MakeDirectory(char *path) {
|
||||
#ifdef WIN32
|
||||
|
||||
void File_IterateDir(char *path,
|
||||
int (*func)(char *path, char *name, void *data), void *data) {
|
||||
int(*func)(char *path, char *name, void *data), void *data) {
|
||||
int handle;
|
||||
struct _finddata_t fileinfo;
|
||||
char f_path[MaxPath];
|
||||
@@ -266,11 +267,10 @@ void File_IterateDir(char *path,
|
||||
if (handle == -1)
|
||||
return;
|
||||
|
||||
// Recorrer el directorio
|
||||
// Iterate directory
|
||||
do {
|
||||
if (strcmp(fileinfo.name, ".") && strcmp(fileinfo.name, "..")) {
|
||||
// A partir de aqui hay un fichero
|
||||
// (o directorio)
|
||||
// Each item
|
||||
snprintf(f_path, 512, "%s/%s", path, fileinfo.name);
|
||||
fin = func(f_path, fileinfo.name, data);
|
||||
}
|
||||
@@ -282,7 +282,7 @@ void File_IterateDir(char *path,
|
||||
#else
|
||||
|
||||
void File_IterateDir(char *path,
|
||||
int (*func)(char *path, char *name, void *data), void *data) {
|
||||
int(*func)(char *path, char *name, void *data), void *data) {
|
||||
DIR *directorio;
|
||||
struct dirent *entidad_dir;
|
||||
char f_path[MaxPath];
|
||||
@@ -290,22 +290,21 @@ void File_IterateDir(char *path,
|
||||
char *ptr;
|
||||
|
||||
directorio = opendir(path);
|
||||
if (directorio == NULL )
|
||||
return;
|
||||
if (directorio == NULL)
|
||||
return;
|
||||
|
||||
// Recorrer el directorio
|
||||
// Iterate directory
|
||||
do {
|
||||
entidad_dir = readdir(directorio);
|
||||
if (entidad_dir != NULL ) {
|
||||
if (entidad_dir != NULL) {
|
||||
if (strcmp(entidad_dir->d_name, ".")
|
||||
&& strcmp(entidad_dir->d_name, "..")) {
|
||||
// A partir de aqui hay un fichero
|
||||
// (o directorio)
|
||||
&& strcmp(entidad_dir->d_name, "..")) {
|
||||
// Each item
|
||||
snprintff(f_path, MaxPath, "%s/%s", path, entidad_dir->d_name);
|
||||
fin = func(f_path, entidad_dir->d_name, data);
|
||||
}
|
||||
}
|
||||
}while (entidad_dir != NULL && !fin);
|
||||
} while (entidad_dir != NULL && !fin);
|
||||
closedir(directorio);
|
||||
}
|
||||
#endif
|
||||
@@ -329,26 +328,32 @@ void File_DeleteDirectory(char *path) {
|
||||
#define MaxBuffer 16384
|
||||
int File_Copy(const char *pathOrig, const char *pathDest) {
|
||||
FILE *fOrig, *fDest;
|
||||
char buffer[MaxBuffer];
|
||||
char *buffer = NULL;
|
||||
int readLen = 0;
|
||||
int writeLen = 0;
|
||||
int ok = 0;
|
||||
|
||||
if ((fOrig = fopen(pathOrig, "rb")) == NULL ) {
|
||||
if ((fOrig = fopen(pathOrig, "rb")) == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if ((fDest = fopen(pathDest, "wb")) == NULL ) {
|
||||
if ((fDest = fopen(pathDest, "wb")) == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
buffer = malloc(sizeof(char)*MaxBuffer);
|
||||
if (buffer == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
do {
|
||||
readLen = fread(&buffer, 1, MaxBuffer, fOrig);
|
||||
readLen = fread(buffer, 1, MaxBuffer, fOrig);
|
||||
if (readLen > 0) {
|
||||
writeLen = fwrite(&buffer, 1, readLen, fDest);
|
||||
if (writeLen != readLen) {
|
||||
// Error
|
||||
fclose(fOrig);
|
||||
fclose(fDest);
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -360,5 +365,6 @@ int File_Copy(const char *pathOrig, const char *pathDest) {
|
||||
|
||||
fclose(fOrig);
|
||||
fclose(fDest);
|
||||
free(buffer);
|
||||
return ok;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user