[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[paragui-cvs] CVS: paragui/src/physfs/platform Makefile.am,1.1.1.1.6.1,1
From: |
Alexander Pipelka <address@hidden> |
Subject: |
[paragui-cvs] CVS: paragui/src/physfs/platform Makefile.am,1.1.1.1.6.1,1.1.1.1.6.2 macclassic.c,1.1.2.1,1.1.2.2 skeleton.c,1.1.2.1,1.1.2.2 unix.c,1.1.1.1.6.1,1.1.1.1.6.2 win32.c,1.1.1.1.6.8,1.1.1.1.6.9 |
Date: |
Fri, 21 Jun 2002 16:07:55 -0400 |
Update of /cvsroot/paragui/paragui/src/physfs/platform
In directory subversions:/tmp/cvs-serv22775/platform
Modified Files:
Tag: devel-1-0
Makefile.am macclassic.c skeleton.c unix.c win32.c
Log Message:
updated phyfs part 1
Index: Makefile.am
===================================================================
RCS file: /cvsroot/paragui/paragui/src/physfs/platform/Makefile.am,v
retrieving revision 1.1.1.1.6.1
retrieving revision 1.1.1.1.6.2
diff -C2 -r1.1.1.1.6.1 -r1.1.1.1.6.2
*** Makefile.am 3 May 2002 10:15:33 -0000 1.1.1.1.6.1
--- Makefile.am 21 Jun 2002 20:07:53 -0000 1.1.1.1.6.2
***************
*** 1,7 ****
EXTRA_DIST = \
! beos.c \
skeleton.c \
macclassic.c \
! unix.c \
! unix_nocdrom.c \
! win32.c
--- 1,19 ----
+ noinst_LTLIBRARIES = libplatform.la
+
+ if BUILD_BEOS_CPP
+ libplatform_la_SOURCES = \
+ posix.c \
+ beos.cpp
+ else
+ libplatform_la_SOURCES = \
+ posix.c \
+ unix.c
+ endif
+
EXTRA_DIST = \
! posix.c \
! unix.c \
skeleton.c \
+ win32.c \
macclassic.c \
! beos.cpp
Index: macclassic.c
===================================================================
RCS file: /cvsroot/paragui/paragui/src/physfs/platform/macclassic.c,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -r1.1.2.1 -r1.1.2.2
*** macclassic.c 3 May 2002 10:15:33 -0000 1.1.2.1
--- macclassic.c 21 Jun 2002 20:07:53 -0000 1.1.2.2
***************
*** 7,10 ****
--- 7,14 ----
*/
+ #if HAVE_CONFIG_H
+ # include <config.h>
+ #endif
+
#include <stdlib.h>
#include <string.h>
***************
*** 801,804 ****
--- 805,834 ----
/* no mutexes on MacOS Classic. */
} /* __PHYSFS_platformReleaseMutex */
+
+
+ PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname)
+ {
+ FSSpec spec;
+ CInfoPBRec infoPB;
+ UInt32 modDate;
+
+ BAIL_IF_MACRO(fnameToFSSpec(fname, &spec) != noErr, ERR_OS_ERROR, -1);
+
+ memset(&infoPB, '\0', sizeof (CInfoPBRec));
+ infoPB.dirInfo.ioNamePtr = spec.name;
+ infoPB.dirInfo.ioVRefNum = spec.vRefNum;
+ infoPB.dirInfo.ioDrDirID = spec.parID;
+ infoPB.dirInfo.ioFDirIndex = 0;
+ BAIL_IF_MACRO(PBGetCatInfoSync(&infoPB) != noErr, ERR_OS_ERROR, -1);
+
+ modDate = ((infoPB.dirInfo.ioFlAttrib & kioFlAttribDirMask) != 0) ?
+ infoPB.dirInfo.ioDrMdDat : infoPB.hFileInfo.ioFlMdDat;
+
+ /* epoch is different on MacOS. They use Jan 1, 1904, apparently. */
+ /* subtract seconds between those epochs, counting leap years. */
+ modDate -= 2082844800;
+
+ return((PHYSFS_sint64) modDate);
+ } /* __PHYSFS_platformGetLastModTime */
/* end of macclassic.c ... */
Index: skeleton.c
===================================================================
RCS file: /cvsroot/paragui/paragui/src/physfs/platform/skeleton.c,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -r1.1.2.1 -r1.1.2.2
*** skeleton.c 3 May 2002 10:15:33 -0000 1.1.2.1
--- skeleton.c 21 Jun 2002 20:07:53 -0000 1.1.2.2
***************
*** 7,10 ****
--- 7,14 ----
*/
+ #if HAVE_CONFIG_H
+ # include <config.h>
+ #endif
+
#define __PHYSICSFS_INTERNAL__
#include "physfs_internal.h"
***************
*** 217,220 ****
--- 221,230 ----
/* not implemented, but can't call __PHYSFS_setError! */
} /* __PHYSFS_platformReleaseMutex */
+
+
+ PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname)
+ {
+ BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
+ } /* __PHYSFS_platformGetLastModTime */
/* end of skeleton.c ... */
Index: unix.c
===================================================================
RCS file: /cvsroot/paragui/paragui/src/physfs/platform/unix.c,v
retrieving revision 1.1.1.1.6.1
retrieving revision 1.1.1.1.6.2
diff -C2 -r1.1.1.1.6.1 -r1.1.1.1.6.2
*** unix.c 3 May 2002 10:15:33 -0000 1.1.1.1.6.1
--- unix.c 21 Jun 2002 20:07:53 -0000 1.1.1.1.6.2
***************
*** 7,10 ****
--- 7,16 ----
*/
+ #if HAVE_CONFIG_H
+ # include <config.h>
+ #endif
+
+ #if (!defined __BEOS__) /* BeOS uses beos.cpp and posix.c ... */
+
#if ((defined __APPLE__) && (defined __MACH__))
# if (!defined __DARWIN__)
***************
*** 13,37 ****
#endif
- #if (defined __STRICT_ANSI__)
- #define __PHYSFS_DOING_STRICT_ANSI__
- #endif
-
- /*
- * We cheat a little: I want the symlink version of stat() (lstat), and
- * GCC/Linux will not declare it if compiled with the -ansi flag.
- * If you are really lacking symlink support on your platform,
- * you should #define __PHYSFS_NO_SYMLINKS__ before compiling this
- * file. That will open a security hole, though, if you really DO have
- * symlinks on your platform; it renders PHYSFS_permitSymbolicLinks(0)
- * useless, since every symlink will be reported as a regular file/dir.
- */
- #if (defined __PHYSFS_DOING_STRICT_ANSI__)
- #undef __STRICT_ANSI__
- #endif
#include <stdio.h>
- #if (defined __PHYSFS_DOING_STRICT_ANSI__)
- #define __STRICT_ANSI__
- #endif
-
#include <stdlib.h>
#include <string.h>
--- 19,23 ----
***************
*** 97,101 ****
else if ( strcmp( mntbufp[ii].f_fstypename, "cd9660") == 0 )
add_it = 1;
! /* !!! other mount types? */
if (add_it)
--- 83,88 ----
else if ( strcmp( mntbufp[ii].f_fstypename, "cd9660") == 0 )
add_it = 1;
!
! /* add other mount types here */
if (add_it)
***************
*** 116,121 ****
}
- free( mntbufp );
-
retval[cd_count - 1] = NULL;
return(retval);
--- 103,106 ----
***************
*** 144,148 ****
if (strcmp(ent->mnt_type, "iso9660") == 0)
add_it = 1;
! /* !!! other mount types? */
if (add_it)
--- 129,134 ----
if (strcmp(ent->mnt_type, "iso9660") == 0)
add_it = 1;
!
! /* add other mount types here */
if (add_it)
***************
*** 171,293 ****
! static char *copyEnvironmentVariable(const char *varname)
! {
! const char *envr = getenv(varname);
! char *retval = NULL;
- if (envr != NULL)
- {
- retval = malloc(strlen(envr) + 1);
- if (retval != NULL)
- strcpy(retval, envr);
- } /* if */
! return(retval);
! } /* copyEnvironmentVariable */
!
!
! /* !!! this is ugly. */
! char *__PHYSFS_platformCalcBaseDir(const char *argv0)
{
! /* If there isn't a path on argv0, then look through the $PATH for it. */
!
! char *retval = NULL;
! char *envr;
! char *start;
char *ptr;
- char *exe;
! if (strchr(argv0, '/') != NULL) /* default behaviour can handle this. */
! return(NULL);
!
! envr = copyEnvironmentVariable("PATH");
! BAIL_IF_MACRO(!envr, NULL, NULL);
- start = envr;
do
{
! ptr = strchr(start, ':');
if (ptr)
*ptr = '\0';
! exe = (char *) malloc(strlen(start) + strlen(argv0) + 2);
! if (!exe)
{
! free(envr);
! BAIL_IF_MACRO(1, ERR_OUT_OF_MEMORY, NULL);
} /* if */
strcpy(exe, start);
if (exe[strlen(exe) - 1] != '/')
strcat(exe, "/");
! strcat(exe, argv0);
! if (access(exe, X_OK) != 0)
! free(exe);
! else
{
! retval = exe;
! strcpy(retval, start); /* i'm lazy. piss off. */
! break;
! } /* else */
! start = ptr + 1;
} while (ptr != NULL);
! free(envr);
! return(retval);
! } /* __PHYSFS_platformCalcBaseDir */
!
!
! static char *getUserNameByUID(void)
! {
! uid_t uid = getuid();
! struct passwd *pw;
! char *retval = NULL;
! pw = getpwuid(uid);
! if ((pw != NULL) && (pw->pw_name != NULL))
! {
! retval = malloc(strlen(pw->pw_name) + 1);
! if (retval != NULL)
! strcpy(retval, pw->pw_name);
! } /* if */
!
! return(retval);
! } /* getUserNameByUID */
! static char *getUserDirByUID(void)
{
! uid_t uid = getuid();
! struct passwd *pw;
! char *retval = NULL;
!
! pw = getpwuid(uid);
! if ((pw != NULL) && (pw->pw_dir != NULL))
! {
! retval = malloc(strlen(pw->pw_dir) + 1);
! if (retval != NULL)
! strcpy(retval, pw->pw_dir);
! } /* if */
!
! return(retval);
! } /* getUserDirByUID */
!
! char *__PHYSFS_platformGetUserName(void)
! {
! char *retval = getUserNameByUID();
! if (retval == NULL)
! retval = copyEnvironmentVariable("USER");
! return(retval);
! } /* __PHYSFS_platformGetUserName */
! char *__PHYSFS_platformGetUserDir(void)
! {
! char *retval = copyEnvironmentVariable("HOME");
! if (retval == NULL)
! retval = getUserDirByUID();
return(retval);
! } /* __PHYSFS_platformGetUserDir */
--- 157,243 ----
! /* this is in posix.c ... */
! extern char *__PHYSFS_platformCopyEnvironmentVariable(const char *varname);
! /*
! * See where program (bin) resides in the $PATH specified by (envr).
! * returns a copy of the first element in envr that contains it, or NULL
! * if it doesn't exist or there were other problems. PHYSFS_SetError() is
! * called if we have a problem.
! *
! * (envr) will be scribbled over, and you are expected to free() the
! * return value when you're done with it.
! */
! static char *findBinaryInPath(const char *bin, char *envr)
{
! size_t alloc_size = 0;
! char *exe = NULL;
! char *start = envr;
char *ptr;
! BAIL_IF_MACRO(bin == NULL, ERR_INVALID_ARGUMENT, NULL);
! BAIL_IF_MACRO(envr == NULL, ERR_INVALID_ARGUMENT, NULL);
do
{
! size_t size;
! ptr = strchr(start, ':'); /* find next $PATH separator. */
if (ptr)
*ptr = '\0';
! size = strlen(start) + strlen(bin) + 2;
! if (size > alloc_size)
{
! char *x = (char *) realloc(exe, size);
! if (x == NULL)
! {
! if (exe != NULL)
! free(exe);
! BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
! } /* if */
!
! alloc_size = size;
! exe = x;
} /* if */
+
+ /* build full binary path... */
strcpy(exe, start);
if (exe[strlen(exe) - 1] != '/')
strcat(exe, "/");
! strcat(exe, bin);
!
! if (access(exe, X_OK) == 0) /* Exists as executable? We're done. */
{
! strcpy(exe, start); /* i'm lazy. piss off. */
! return(exe);
! } /* if */
! start = ptr + 1; /* start points to beginning of next element. */
} while (ptr != NULL);
! if (exe != NULL)
! free(exe);
! return(NULL); /* doesn't exist in path. */
! } /* findBinaryInPath */
! char *__PHYSFS_platformCalcBaseDir(const char *argv0)
{
! /* If there isn't a path on argv0, then look through the $PATH for it. */
! char *retval;
! char *envr;
+ if (strchr(argv0, '/') != NULL) /* default behaviour can handle this. */
+ return(NULL);
! envr = __PHYSFS_platformCopyEnvironmentVariable("PATH");
! BAIL_IF_MACRO(!envr, NULL, NULL);
! retval = findBinaryInPath(argv0, envr);
! free(envr);
return(retval);
! } /* __PHYSFS_platformCalcBaseDir */
***************
*** 298,392 ****
- /* -ansi and -pedantic flags prevent use of strcasecmp() on Linux. */
- int __PHYSFS_platformStricmp(const char *x, const char *y)
- {
- int ux, uy;
-
- do
- {
- ux = toupper((int) *x);
- uy = toupper((int) *y);
- if (ux > uy)
- return(1);
- else if (ux < uy)
- return(-1);
- x++;
- y++;
- } while ((ux) && (uy));
-
- return(0);
- } /* __PHYSFS_platformStricmp */
-
-
- int __PHYSFS_platformExists(const char *fname)
- {
- struct stat statbuf;
- return(stat(fname, &statbuf) == 0);
- } /* __PHYSFS_platformExists */
-
-
- int __PHYSFS_platformIsSymLink(const char *fname)
- {
- #if (defined __PHYSFS_NO_SYMLINKS__)
- return(0);
- #else
-
- struct stat statbuf;
- int retval = 0;
-
- if (lstat(fname, &statbuf) == 0)
- {
- if (S_ISLNK(statbuf.st_mode))
- retval = 1;
- } /* if */
-
- return(retval);
-
- #endif
- } /* __PHYSFS_platformIsSymlink */
-
-
- int __PHYSFS_platformIsDirectory(const char *fname)
- {
- struct stat statbuf;
- int retval = 0;
-
- if (stat(fname, &statbuf) == 0)
- {
- if (S_ISDIR(statbuf.st_mode))
- retval = 1;
- } /* if */
-
- return(retval);
- } /* __PHYSFS_platformIsDirectory */
-
-
- char *__PHYSFS_platformCvtToDependent(const char *prepend,
- const char *dirName,
- const char *append)
- {
- int len = ((prepend) ? strlen(prepend) : 0) +
- ((append) ? strlen(append) : 0) +
- strlen(dirName) + 1;
- char *retval = malloc(len);
-
- BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
-
- /* platform-independent notation is Unix-style already. :) */
-
- if (prepend)
- strcpy(retval, prepend);
- else
- retval[0] = '\0';
-
- strcat(retval, dirName);
-
- if (append)
- strcat(retval, append);
-
- return(retval);
- } /* __PHYSFS_platformCvtToDependent */
-
-
/* Much like my college days, try to sleep for 10 milliseconds at a time... */
void __PHYSFS_platformTimeslice(void)
--- 248,251 ----
***************
*** 396,530 ****
- LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
- int omitSymLinks)
- {
- LinkedStringList *retval = NULL;
- LinkedStringList *l = NULL;
- LinkedStringList *prev = NULL;
- DIR *dir;
- struct dirent *ent;
- int bufsize = 0;
- char *buf = NULL;
- int dlen = 0;
-
- if (omitSymLinks)
- {
- dlen = strlen(dirname);
- bufsize = dlen + 256;
- buf = malloc(bufsize);
- BAIL_IF_MACRO(buf == NULL, ERR_OUT_OF_MEMORY, NULL);
- strcpy(buf, dirname);
- if (buf[dlen - 1] != '/')
- {
- buf[dlen++] = '/';
- buf[dlen] = '\0';
- } /* if */
- } /* if */
-
- errno = 0;
- dir = opendir(dirname);
- if (dir == NULL)
- {
- if (buf != NULL)
- free(buf);
- BAIL_IF_MACRO(1, strerror(errno), NULL);
- } /* if */
-
- while (1)
- {
- ent = readdir(dir);
- if (ent == NULL) /* we're done. */
- break;
-
- if (strcmp(ent->d_name, ".") == 0)
- continue;
-
- if (strcmp(ent->d_name, "..") == 0)
- continue;
-
- if (omitSymLinks)
- {
- char *p;
- int len = strlen(ent->d_name) + dlen + 1;
- if (len > bufsize)
- {
- p = realloc(buf, len);
- if (p == NULL)
- continue;
- buf = p;
- bufsize = len;
- } /* if */
-
- strcpy(buf + dlen, ent->d_name);
- if (__PHYSFS_platformIsSymLink(buf))
- continue;
- } /* if */
-
- l = (LinkedStringList *) malloc(sizeof (LinkedStringList));
- if (l == NULL)
- break;
-
- l->str = (char *) malloc(strlen(ent->d_name) + 1);
- if (l->str == NULL)
- {
- free(l);
- break;
- } /* if */
-
- strcpy(l->str, ent->d_name);
-
- if (retval == NULL)
- retval = l;
- else
- prev->next = l;
-
- prev = l;
- l->next = NULL;
- } /* while */
-
- if (buf != NULL)
- free(buf);
-
- closedir(dir);
- return(retval);
- } /* __PHYSFS_platformEnumerateFiles */
-
-
- char *__PHYSFS_platformCurrentDir(void)
- {
- int allocSize = 0;
- char *retval = NULL;
- char *ptr;
-
- do
- {
- allocSize += 100;
- ptr = (char *) realloc(retval, allocSize);
- if (ptr == NULL)
- {
- if (retval != NULL)
- free(retval);
- BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
- } /* if */
-
- retval = ptr;
- ptr = getcwd(retval, allocSize);
- } while (ptr == NULL && errno == ERANGE);
-
- if (ptr == NULL && errno)
- {
- /*
- * getcwd() failed for some reason, for example current
- * directory not existing.
- */
- if (retval != NULL)
- free(retval);
- BAIL_MACRO(ERR_NO_SUCH_FILE, NULL);
- } /* if */
-
- return(retval);
- } /* __PHYSFS_platformCurrentDir */
-
-
char *__PHYSFS_platformRealPath(const char *path)
{
--- 255,258 ----
***************
*** 534,538 ****
errno = 0;
BAIL_IF_MACRO(!realpath(path, resolved_path), strerror(errno), NULL);
! retval = malloc(strlen(resolved_path) + 1);
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
strcpy(retval, resolved_path);
--- 262,266 ----
errno = 0;
BAIL_IF_MACRO(!realpath(path, resolved_path), strerror(errno), NULL);
! retval = (char *) malloc(strlen(resolved_path) + 1);
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
strcpy(retval, resolved_path);
***************
*** 541,674 ****
- int __PHYSFS_platformMkDir(const char *path)
- {
- int rc;
- errno = 0;
- rc = mkdir(path, S_IRWXU);
- BAIL_IF_MACRO(rc == -1, strerror(errno), 0);
- return(1);
- } /* __PHYSFS_platformMkDir */
-
-
- static void *doOpen(const char *filename, const char *mode)
- {
- FILE *retval;
- errno = 0;
-
- retval = fopen(filename, mode);
- if (retval == NULL)
- __PHYSFS_setError(strerror(errno));
-
- return((void *) retval);
- } /* doOpen */
-
-
- void *__PHYSFS_platformOpenRead(const char *filename)
- {
- return(doOpen(filename, "rb"));
- } /* __PHYSFS_platformOpenRead */
-
-
- void *__PHYSFS_platformOpenWrite(const char *filename)
- {
- return(doOpen(filename, "wb"));
- } /* __PHYSFS_platformOpenWrite */
-
-
- void *__PHYSFS_platformOpenAppend(const char *filename)
- {
- return(doOpen(filename, "wb+"));
- } /* __PHYSFS_platformOpenAppend */
-
-
- PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
- PHYSFS_uint32 size, PHYSFS_uint32 count)
- {
- FILE *io = (FILE *) opaque;
- int rc = fread(buffer, size, count, io);
- if (rc < count)
- {
- int err = errno;
- BAIL_IF_MACRO(ferror(io), strerror(err), rc);
- BAIL_MACRO(ERR_PAST_EOF, rc);
- } /* if */
-
- return(rc);
- } /* __PHYSFS_platformRead */
-
-
- PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
- PHYSFS_uint32 size, PHYSFS_uint32 count)
- {
- FILE *io = (FILE *) opaque;
- int rc = fwrite((void *) buffer, size, count, io);
- if (rc < count)
- __PHYSFS_setError(strerror(errno));
-
- return(rc);
- } /* __PHYSFS_platformWrite */
-
-
- int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
- {
- FILE *io = (FILE *) opaque;
-
- /* !!! FIXME: Use llseek where available. */
- errno = 0;
- BAIL_IF_MACRO(fseek(io, pos, SEEK_SET) != 0, strerror(errno), 0);
-
- return(1);
- } /* __PHYSFS_platformSeek */
-
-
- PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
- {
- FILE *io = (FILE *) opaque;
- PHYSFS_sint64 retval = ftell(io);
- BAIL_IF_MACRO(retval == -1, strerror(errno), -1);
- return(retval);
- } /* __PHYSFS_platformTell */
-
-
- PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque)
- {
- FILE *io = (FILE *) opaque;
- struct stat statbuf;
- errno = 0;
- BAIL_IF_MACRO(fstat(fileno(io), &statbuf) == -1, strerror(errno), -1);
- return((PHYSFS_sint64) statbuf.st_size);
- } /* __PHYSFS_platformFileLength */
-
-
- int __PHYSFS_platformEOF(void *opaque)
- {
- return(feof((FILE *) opaque));
- } /* __PHYSFS_platformEOF */
-
-
- int __PHYSFS_platformFlush(void *opaque)
- {
- errno = 0;
- BAIL_IF_MACRO(fflush((FILE *) opaque) == EOF, strerror(errno), 0);
- return(1);
- } /* __PHYSFS_platformFlush */
-
-
- int __PHYSFS_platformClose(void *opaque)
- {
- errno = 0;
- BAIL_IF_MACRO(fclose((FILE *) opaque) == EOF, strerror(errno), 0);
- return(1);
- } /* __PHYSFS_platformClose */
-
-
- int __PHYSFS_platformDelete(const char *path)
- {
- errno = 0;
- BAIL_IF_MACRO(remove(path) == -1, strerror(errno), 0);
- return(1);
- } /* __PHYSFS_platformDelete */
-
-
void *__PHYSFS_platformCreateMutex(void)
{
--- 269,272 ----
***************
*** 704,707 ****
--- 302,307 ----
pthread_mutex_unlock((pthread_mutex_t *) mutex);
} /* __PHYSFS_platformReleaseMutex */
+
+ #endif /* !defined __BEOS__ */
/* end of unix.c ... */
Index: win32.c
===================================================================
RCS file: /cvsroot/paragui/paragui/src/physfs/platform/win32.c,v
retrieving revision 1.1.1.1.6.8
retrieving revision 1.1.1.1.6.9
diff -C2 -r1.1.1.1.6.8 -r1.1.1.1.6.9
*** win32.c 20 Jun 2002 12:20:34 -0000 1.1.1.1.6.8
--- win32.c 21 Jun 2002 20:07:53 -0000 1.1.1.1.6.9
***************
*** 1,30 ****
/*
! * Win32 platform-dependent support routines for PhysicsFS.
*
* Please see the file LICENSE in the source's root directory.
*
! * This file written by Ryan C. Gordon.
! * Modified for ParaGUI by Alexander Pipelka
*/
#include <windows.h>
- #include <lm.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define __PHYSICSFS_INTERNAL__
#include "physfs_internal.h"
-
- const char *__PHYSFS_platformDirSeparator = "\\";
-
- static HANDLE ProcessHandle = NULL; /* Current process handle */
- static DWORD ProcessID; /* ID assigned to current process */
-
#define LOWORDER_UINT64(pos) (PHYSFS_uint32)(pos & 0x00000000FFFFFFFF)
#define HIGHORDER_UINT64(pos) (PHYSFS_uint32)(pos & 0xFFFFFFFF00000000)
- #define INVALID_SET_FILE_POINTER ((DWORD)-1)
static const char *win32strerror(void)
{
--- 1,47 ----
/*
! * Win32 support routines for PhysicsFS.
*
* Please see the file LICENSE in the source's root directory.
*
! * This file written by Ryan C. Gordon, and made sane by Gregory S. Read.
*/
+ #if HAVE_CONFIG_H
+ # include <config.h>
+ #endif
+
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
+ #include <time.h>
+ #include <assert.h>
#define __PHYSICSFS_INTERNAL__
#include "physfs_internal.h"
#define LOWORDER_UINT64(pos) (PHYSFS_uint32)(pos & 0x00000000FFFFFFFF)
#define HIGHORDER_UINT64(pos) (PHYSFS_uint32)(pos & 0xFFFFFFFF00000000)
+ const char *__PHYSFS_platformDirSeparator = "\\";
+
+ static int runningNT = 0; /* TRUE if NT derived OS */
+ static OSVERSIONINFO OSVersionInfo; /* Information about the OS */
+ static char *ProfileDirectory = NULL; /* User profile folder */
+
+ /* Users without the platform SDK don't have this defined. The original docs
+ for SetFilePointer() just said to compare with 0xFFFFFFF, so this should
+ work as desired */
+ #ifndef INVALID_SET_FILE_POINTER
+ #define INVALID_SET_FILE_POINTER 0xFFFFFFFF
+ #endif
+
+ /*
+ * Figure out what the last failing Win32 API call was, and
+ * generate a human-readable string for the error message.
+ *
+ * The return value is a static buffer that is overwritten with
+ * each call to this function.
+ */
static const char *win32strerror(void)
{
***************
*** 46,79 ****
! int __PHYSFS_platformInit(void)
{
! char* basedir = NULL;
- /* Get Windows ProcessID associated with the current process */
- ProcessID = GetCurrentProcessId();
/* Create a process handle associated with the current process ID */
ProcessHandle = GetCurrentProcess();
! if(ProcessHandle == NULL) {
! /* Process handle is required by other win32 functions */
! return 0;
! }
! basedir = __PHYSFS_platformCalcBaseDir("");
! SetCurrentDirectory(basedir);
! return(1);
! } /* __PHYSFS_platformInit */
! int __PHYSFS_platformDeinit(void)
{
! if(CloseHandle(ProcessHandle) != S_OK)
! return 0;
! /* It's all good */
! return 1;
! } /* __PHYSFS_platformDeinit */
char **__PHYSFS_platformDetectAvailableCDs(void)
--- 63,176 ----
! /*
! * Uninitialize any NT specific stuff done in doNTInit().
! *
! * Return zero if there was a catastrophic failure and non-zero otherwise.
! */
! static int doNTDeinit(void)
{
! /* nothing NT-specific to deinit at this point. */
! return 1; /* It's all good */
! } /* doNTDeinit */
!
!
! typedef BOOL (STDMETHODCALLTYPE FAR * LPFNGETUSERPROFILEDIR) (
! HANDLE hToken,
! LPTSTR lpProfileDir,
! LPDWORD lpcchSize);
!
! /*
! * Initialize any NT specific stuff. This includes any OS based on NT.
! *
! * Return zero if there was a catastrophic failure and non-zero otherwise.
! */
! static int doNTInit(void)
! {
! DWORD pathsize = 0;
! char dummy[1];
! BOOL rc = 0;
! HANDLE ProcessHandle = NULL; /* Current process handle */
! HANDLE AccessTokenHandle = NULL; /* Security handle to process */
! LPFNGETUSERPROFILEDIR GetUserProfileDirectory = NULL;
! HMODULE lib = NULL;
! const char *err = NULL;
!
! /* Hooray for spaghetti code! */
!
! lib = LoadLibrary("userenv.dll");
! if (!lib)
! goto ntinit_failed;
!
! /* !!! FIXME: Handle Unicode? */
! GetUserProfileDirectory = (LPFNGETUSERPROFILEDIR)
! GetProcAddress(lib, "GetUserProfileDirectoryA");
! if (!GetUserProfileDirectory)
! goto ntinit_failed;
/* Create a process handle associated with the current process ID */
ProcessHandle = GetCurrentProcess();
! /* Create a process access token handle */
! if(!OpenProcessToken(ProcessHandle, TOKEN_QUERY, &AccessTokenHandle))
! goto ntinit_failed; /* we need that token to get the profile dir. */
!
! /* Should fail. Will write the size of the profile path in pathsize */
! /* Second parameter can't be NULL or the function fails. */
! rc = GetUserProfileDirectory(AccessTokenHandle, dummy, &pathsize);
! assert(!rc); /* success?! */
!
! /* Allocate memory for the profile directory */
! ProfileDirectory = (char *) malloc(pathsize);
! if (ProfileDirectory == NULL)
! {
! err = ERR_OUT_OF_MEMORY;
! goto ntinit_failed;
! } /* if */
! /* Try to get the profile directory */
! if(!GetUserProfileDirectory(AccessTokenHandle, ProfileDirectory,
&pathsize))
! goto ntinit_failed;
! goto ntinit_succeeded; /* We made it: hit the showers. */
+ ntinit_failed:
+ if (err == NULL) /* set an error string if we haven't yet. */
+ __PHYSFS_setError(win32strerror());
! if (ProfileDirectory != NULL)
! {
! free(ProfileDirectory);
! ProfileDirectory = NULL;
! } /* if */
!
! /* drop through and clean up the rest of the stuff... */
!
! ntinit_succeeded:
! if (lib != NULL)
! FreeLibrary(lib);
!
! if (AccessTokenHandle != NULL)
! CloseHandle(AccessTokenHandle);
!
! return ((err == NULL) ? 1 : 0);
! } /* doNTInit */
!
! static BOOL MediaInDrive(const char *DriveLetter)
{
! UINT OldErrorMode;
! DWORD DummyValue;
! BOOL ReturnValue;
! /* Prevent windows warning message to appear when checking media size */
! OldErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
!
! /* If this function succeeds, there's media in the drive */
! ReturnValue = GetDiskFreeSpace(DriveLetter, &DummyValue, &DummyValue,
&DummyValue, &DummyValue);
!
! /* Revert back to old windows error handler */
! SetErrorMode(OldErrorMode);
+ return ReturnValue;
+ } /* MediaInDrive */
char **__PHYSFS_platformDetectAvailableCDs(void)
***************
*** 85,89 ****
for (drive_str[0] = 'A'; drive_str[0] <= 'Z'; drive_str[0]++)
{
! if (GetDriveType(drive_str) == DRIVE_CDROM)
{
char **tmp = realloc(retval, sizeof (char *) * cd_count + 1);
--- 182,186 ----
for (drive_str[0] = 'A'; drive_str[0] <= 'Z'; drive_str[0]++)
{
! if (GetDriveType(drive_str) == DRIVE_CDROM && MediaInDrive(drive_str))
{
char **tmp = realloc(retval, sizeof (char *) * cd_count + 1);
***************
*** 103,107 ****
retval[cd_count - 1] = NULL;
return(retval);
! } /* __PHYSFS_platformDetectAvailableCDs */
--- 200,204 ----
retval[cd_count - 1] = NULL;
return(retval);
! } /* __PHYSFS_detectAvailableCDs */
***************
*** 109,122 ****
{
char *filepart = NULL;
! char *retval = (char *) malloc(sizeof (TCHAR) * (MAX_PATH + 1));
! DWORD buflen = GetModuleFileName(NULL, retval, MAX_PATH + 1);
! char *ptr;
retval[buflen] = '\0'; /* does API always null-terminate the string? */
! /* make sure the string was not truncated. */
if (__PHYSFS_platformStricmp(&retval[buflen - 4], ".exe") == 0)
{
! ptr = strrchr(retval, '\\');
if (ptr != NULL)
{
--- 206,228 ----
{
char *filepart = NULL;
! char *retval;
! DWORD buflen;
!
! retval = (char *) malloc(sizeof (TCHAR) * (MAX_PATH + 1));
! BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
! buflen = GetModuleFileName(NULL, retval, MAX_PATH + 1);
! if (buflen == 0)
! {
! const char *err = win32strerror();
! free(retval);
! BAIL_MACRO(err, NULL);
! } /* if */
retval[buflen] = '\0'; /* does API always null-terminate the string? */
! /* make sure the string was not truncated. */
if (__PHYSFS_platformStricmp(&retval[buflen - 4], ".exe") == 0)
{
! char *ptr = strrchr(retval, '\\');
if (ptr != NULL)
{
***************
*** 124,130 ****
/* free up the bytes we didn't actually use. */
! retval = (char *) realloc(retval, strlen(retval) + 1);
! if (retval != NULL)
! return(retval);
} /* if */
} /* if */
--- 230,238 ----
/* free up the bytes we didn't actually use. */
! ptr = (char *) realloc(retval, strlen(retval) + 1);
! if (ptr != NULL)
! retval = ptr;
!
! return(retval);
} /* if */
} /* if */
***************
*** 160,163 ****
--- 268,272 ----
if (GetUserName(retval, &bufsize) == 0) /* ?! */
{
+ __PHYSFS_setError(win32strerror());
free(retval);
retval = NULL;
***************
*** 169,221 ****
- static char *copyEnvironmentVariable(const char *varname)
- {
- const char *envr = getenv(varname);
- char *retval = NULL;
-
- if (envr != NULL)
- {
- retval = malloc(strlen(envr) + 1);
- if (retval != NULL)
- strcpy(retval, envr);
- } /* if */
-
- return(retval);
- } /* copyEnvironmentVariable */
-
-
char *__PHYSFS_platformGetUserDir(void)
{
! char *home = NULL;
! const char *homedrive = getenv("HOMEDRIVE");
! const char *homepath = getenv("HOMEPATH");
!
! if(getenv("USERPROFILE") != NULL) {
! home = copyEnvironmentVariable("USERPROFILE");
! return home;
! }
!
! home = copyEnvironmentVariable("HOME");
!
! if (home != NULL)
! return(home);
!
! if ((homedrive != NULL) && (homepath != NULL))
! {
! char *retval = (char *) malloc(strlen(homedrive)+strlen(homepath)+2);
! if (retval != NULL)
! {
! strcpy(retval, homedrive);
! if ((homepath[0] != '\\') &&
! (homedrive[strlen(homedrive)-1] != '\\'))
! {
! strcat(retval, "\\");
! } /* if */
! strcat(retval, homepath);
! return(retval);
! } /* if */
! } /* if */
!
! return(NULL);
} /* __PHYSFS_platformGetUserDir */
--- 278,287 ----
char *__PHYSFS_platformGetUserDir(void)
{
! char *retval = (char *) malloc(strlen(ProfileDirectory) + 1);
! BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
! strcpy(retval, ProfileDirectory); /* calculated at init time. */
! return retval;
} /* __PHYSFS_platformGetUserDir */
***************
*** 223,232 ****
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
{
! return((int) GetCurrentThreadId());
} /* __PHYSFS_platformGetThreadID */
int __PHYSFS_platformStricmp(const char *x, const char *y)
{
int ux, uy;
--- 289,302 ----
PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
{
! return((PHYSFS_uint64)GetCurrentThreadId());
} /* __PHYSFS_platformGetThreadID */
+ /* ...make this Cygwin AND Visual C friendly... */
int __PHYSFS_platformStricmp(const char *x, const char *y)
{
+ #if (defined _MSC_VER)
+ return(stricmp(x, y));
+ #else
int ux, uy;
***************
*** 244,247 ****
--- 314,318 ----
return(0);
+ #endif
} /* __PHYSFS_platformStricmp */
***************
*** 294,297 ****
--- 365,369 ----
+ /* Much like my college days, try to sleep for 10 milliseconds at a time... */
void __PHYSFS_platformTimeslice(void)
{
***************
*** 308,315 ****
HANDLE dir;
WIN32_FIND_DATA ent;
! char path[255];
! sprintf(path, "%s\\*.*", dirname);
! dir = FindFirstFile(path, &ent);
BAIL_IF_MACRO(dir == INVALID_HANDLE_VALUE, win32strerror(), NULL);
--- 380,404 ----
HANDLE dir;
WIN32_FIND_DATA ent;
! char *SearchPath;
! size_t len = strlen(dirname);
!
! /* Allocate a new string for path, maybe '\\', "*", and NULL terminator */
! SearchPath = (char *) _alloca(len + 3);
! BAIL_IF_MACRO(SearchPath == NULL, ERR_OUT_OF_MEMORY, NULL);
!
! /* Copy current dirname */
! strcpy(SearchPath, dirname);
!
! /* if there's no '\\' at the end of the path, stick one in there. */
! if (SearchPath[len - 1] != '\\')
! {
! SearchPath[len++] = '\\';
! SearchPath[len] = '\0';
! } /* if */
!
! /* Append the "*" to the end of the string */
! strcat(SearchPath, "*");
! dir = FindFirstFile(SearchPath, &ent);
BAIL_IF_MACRO(dir == INVALID_HANDLE_VALUE, win32strerror(), NULL);
***************
*** 342,346 ****
prev = l;
l->next = NULL;
! } while( FindNextFile(dir, &ent) != 0 );
FindClose(dir);
--- 431,435 ----
prev = l;
l->next = NULL;
! } while (FindNextFile(dir, &ent) != 0);
FindClose(dir);
***************
*** 366,369 ****
--- 455,459 ----
+ /* this could probably use a cleanup. */
char *__PHYSFS_platformRealPath(const char *path)
{
***************
*** 382,389 ****
*/
if ((path[0] == '\\') && (path[1] == '\\'))
- {
- BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
strcpy(retval, path);
- } /* if */
else
--- 472,476 ----
***************
*** 497,500 ****
--- 584,640 ----
+ /*
+ * Get OS info and save it.
+ *
+ * Returns non-zero if successful, otherwise it returns zero on failure.
+ */
+ int getOSInfo(void)
+ {
+ /* Get OS info */
+ OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVersionInfo);
+ BAIL_IF_MACRO(!GetVersionEx(&OSVersionInfo), win32strerror(), 0);
+
+ /* Set to TRUE if we are runnign a WinNT based OS 4.0 or greater */
+ runningNT = (OSVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) &&
+ (OSVersionInfo.dwMajorVersion > 3);
+
+ return 1;
+ }
+
+ int __PHYSFS_platformInit(void)
+ {
+ BAIL_IF_MACRO(!getOSInfo(), NULL, 0);
+
+ /* If running an NT system (NT/Win2k/XP, etc...) */
+ if(runningNT)
+ {
+ BAIL_IF_MACRO(!doNTInit(), NULL, 0);
+ } /* if */
+ else
+ {
+ /* Profile directory is the exe path on 95/98/ME systems. */
+ ProfileDirectory = getExePath(NULL);
+ BAIL_IF_MACRO(ProfileDirectory == NULL, win32strerror(), 0);
+ } /* else */
+
+ return 1; /* It's all good */
+ }
+
+ int __PHYSFS_platformDeinit(void)
+ {
+ if (runningNT)
+ {
+ BAIL_IF_MACRO(!doNTDeinit(), NULL, 0);
+ } /* if */
+
+ if (ProfileDirectory != NULL)
+ {
+ free(ProfileDirectory);
+ ProfileDirectory = NULL;
+ } /* if */
+
+ return 1; /* It's all good */
+ }
+
void *__PHYSFS_platformOpenRead(const char *filename)
{
***************
*** 506,516 ****
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
! /* If CreateFile() failed */
! if(FileHandle == INVALID_HANDLE_VALUE)
! return NULL;
!
return (void *)FileHandle;
! } /* __PHYSFS_platformOpenRead */
!
void *__PHYSFS_platformOpenWrite(const char *filename)
--- 646,652 ----
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
! BAIL_IF_MACRO(FileHandle == INVALID_HANDLE_VALUE, win32strerror(), NULL);
return (void *)FileHandle;
! }
void *__PHYSFS_platformOpenWrite(const char *filename)
***************
*** 523,533 ****
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
! /* If CreateFile() failed */
! if(FileHandle == INVALID_HANDLE_VALUE)
! return NULL;
!
return (void *)FileHandle;
! } /* __PHYSFS_platformOpenWrite */
!
void *__PHYSFS_platformOpenAppend(const char *filename)
--- 659,665 ----
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
! BAIL_IF_MACRO(FileHandle == INVALID_HANDLE_VALUE, win32strerror(), NULL);
return (void *)FileHandle;
! }
void *__PHYSFS_platformOpenAppend(const char *filename)
***************
*** 538,552 ****
who request read access to the file only. */
FileHandle = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL,
! TRUNCATE_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
!
! /* If CreateFile() failed */
! if(FileHandle == INVALID_HANDLE_VALUE)
! /* CreateFile might have failed because the file doesn't exist, so
! we'll just create a new file for writing then */
! return __PHYSFS_platformOpenWrite(filename);
return (void *)FileHandle;
! } /* __PHYSFS_platformOpenAppend */
!
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
--- 670,678 ----
who request read access to the file only. */
FileHandle = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL,
! OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+ BAIL_IF_MACRO(FileHandle == INVALID_HANDLE_VALUE, win32strerror(), NULL);
return (void *)FileHandle;
! }
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer,
***************
*** 564,572 ****
if(!ReadFile(FileHandle, buffer, count * size, &CountOfBytesRead, NULL))
{
! /* Set the error to GetLastError */
! __PHYSFS_setError(win32strerror());
! /* We errored out */
! retval = -1;
! }
else
{
--- 690,695 ----
if(!ReadFile(FileHandle, buffer, count * size, &CountOfBytesRead, NULL))
{
! BAIL_MACRO(win32strerror(), -1);
! } /* if */
else
{
***************
*** 574,584 ****
/* !!! - What if not the right amount of bytes was read to make an
object? */
retval = CountOfBytesRead / size;
! }
return retval;
! } /* __PHYSFS_platformRead */
!
! PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
PHYSFS_uint32 size, PHYSFS_uint32 count)
{
--- 697,706 ----
/* !!! - What if not the right amount of bytes was read to make an
object? */
retval = CountOfBytesRead / size;
! } /* else */
return retval;
! }
! PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, void *buffer,
PHYSFS_uint32 size, PHYSFS_uint32 count)
{
***************
*** 594,602 ****
if(!WriteFile(FileHandle, buffer, count * size, &CountOfBytesWritten,
NULL))
{
! /* Set the error to GetLastError */
! __PHYSFS_setError(win32strerror());
! /* We errored out */
! retval = -1;
! }
else
{
--- 716,721 ----
if(!WriteFile(FileHandle, buffer, count * size, &CountOfBytesWritten,
NULL))
{
! BAIL_MACRO(win32strerror(), -1);
! } /* if */
else
{
***************
*** 604,612 ****
/*!!! - What if not the right number of bytes was written? */
retval = CountOfBytesWritten / size;
! }
return retval;
! } /* __PHYSFS_platformWrite */
!
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
--- 723,730 ----
/*!!! - What if not the right number of bytes was written? */
retval = CountOfBytesWritten / size;
! } /* else */
return retval;
! }
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos)
***************
*** 639,648 ****
return retval;
! } /* __PHYSFS_platformSeek */
!
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
{
HANDLE FileHandle;
PHYSFS_sint64 retval;
--- 757,767 ----
return retval;
! }
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque)
{
HANDLE FileHandle;
+ DWORD HighOrderPos = 0;
+ DWORD LowOrderPos;
PHYSFS_sint64 retval;
***************
*** 651,675 ****
/* Get current position */
! retval = SetFilePointer(FileHandle, 0, NULL, FILE_CURRENT);
! /* if(GetLastError() != NO_ERROR)
{
__PHYSFS_setError(win32strerror());
retval = 0;
}
! */
return retval;
! } /* __PHYSFS_platformTell */
!
PHYSFS_sint64 __PHYSFS_platformFileLength(void *handle)
{
HANDLE FileHandle;
/* Cast the generic handle to a Win32 handle */
! FileHandle = (HANDLE)handle;
! return GetFileSize(FileHandle, NULL);
! } /* __PHYSFS_platformFileLength */
int __PHYSFS_platformEOF(void *opaque)
--- 770,819 ----
/* Get current position */
! if(((LowOrderPos = SetFilePointer(FileHandle, 0, &HighOrderPos,
FILE_CURRENT))
! == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
{
+ /* Set the error to GetLastError */
__PHYSFS_setError(win32strerror());
+ /* We errored out */
retval = 0;
}
! else
! {
! /* Combine the high/low order to create the 64-bit position value */
! retval = HighOrderPos;
! retval = retval << 32;
! retval |= LowOrderPos;
! }
+ /*!!! Can't find a file pointer routine?!?!?!!?!?*/
return retval;
! }
PHYSFS_sint64 __PHYSFS_platformFileLength(void *handle)
{
HANDLE FileHandle;
+ DWORD FileSizeHigh;
+ DWORD FileSizeLow;
+ PHYSFS_sint64 retval;
/* Cast the generic handle to a Win32 handle */
! FileHandle = (HANDLE)handle;
+ /* Get the file size. Condition evaluates to TRUE if an error occured */
+ if(((FileSizeLow = GetFileSize(FileHandle, &FileSizeHigh))
+ == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
+ {
+ BAIL_MACRO(win32strerror(), -1);
+ } /* if */
+ else
+ {
+ /* Combine the high/low order to create the 64-bit position value */
+ retval = FileSizeHigh;
+ retval = retval << 32;
+ retval |= FileSizeLow;
+ } /* else */
+
+ return retval;
+ }
int __PHYSFS_platformEOF(void *opaque)
***************
*** 682,694 ****
FileHandle = (HANDLE)opaque;
- if(__PHYSFS_platformFileLength(FileHandle) == -1) {
- return 1;
- }
-
/* Get the current position in the file */
! FilePosition = __PHYSFS_platformTell(FileHandle);
! return (FilePosition >= (__PHYSFS_platformFileLength(FileHandle) - 1));
! } /* __PHYSFS_platformEOF */
int __PHYSFS_platformFlush(void *opaque)
--- 826,838 ----
FileHandle = (HANDLE)opaque;
/* Get the current position in the file */
! if((FilePosition = __PHYSFS_platformTell(opaque)) != 0)
! {
! /* Non-zero if EOF is equal to the file length */
! retval = FilePosition == __PHYSFS_platformFileLength(opaque);
! }
+ return retval;
+ }
int __PHYSFS_platformFlush(void *opaque)
***************
*** 708,713 ****
return retval;
! } /* __PHYSFS_platformFlush */
!
int __PHYSFS_platformClose(void *opaque)
--- 852,856 ----
return retval;
! }
int __PHYSFS_platformClose(void *opaque)
***************
*** 727,732 ****
return retval;
! } /* __PHYSFS_platformClose */
!
int __PHYSFS_platformDelete(const char *path)
--- 870,874 ----
return retval;
! }
int __PHYSFS_platformDelete(const char *path)
***************
*** 751,768 ****
return retval;
! } /* __PHYSFS_platformDelete */
!
void *__PHYSFS_platformCreateMutex(void)
{
return (void *)CreateMutex(NULL, FALSE, NULL);
! } /* __PHYSFS_platformCreateMutex */
!
void __PHYSFS_platformDestroyMutex(void *mutex)
{
CloseHandle((HANDLE)mutex);
! } /* __PHYSFS_platformDestroyMutex */
!
int __PHYSFS_platformGrabMutex(void *mutex)
--- 893,907 ----
return retval;
! }
void *__PHYSFS_platformCreateMutex(void)
{
return (void *)CreateMutex(NULL, FALSE, NULL);
! }
void __PHYSFS_platformDestroyMutex(void *mutex)
{
CloseHandle((HANDLE)mutex);
! }
int __PHYSFS_platformGrabMutex(void *mutex)
***************
*** 773,792 ****
{
/* Our wait failed for some unknown reason */
! retval = 1;
}
else
{
/* Good to go */
! retval = 0;
}
return retval;
! } /* __PHYSFS_platformGrabMutex */
!
void __PHYSFS_platformReleaseMutex(void *mutex)
{
ReleaseMutex((HANDLE)mutex);
! } /* __PHYSFS_platformReleaseMutex */
/* end of win32.c ... */
--- 912,971 ----
{
/* Our wait failed for some unknown reason */
! retval = 0;
}
else
{
/* Good to go */
! retval = 1;
}
return retval;
! }
void __PHYSFS_platformReleaseMutex(void *mutex)
{
ReleaseMutex((HANDLE)mutex);
! }
!
! static time_t FileTimeToTimeT(FILETIME *ft)
! {
! SYSTEMTIME st_utc;
! SYSTEMTIME st_localtz;
! TIME_ZONE_INFORMATION TimeZoneInfo;
! struct tm tm;
!
! FileTimeToSystemTime(ft, &st_utc);
! GetTimeZoneInformation(&TimeZoneInfo);
! SystemTimeToTzSpecificLocalTime(&TimeZoneInfo, &st_utc, &st_localtz);
!
! tm.tm_sec = st_localtz.wSecond;
! tm.tm_min = st_localtz.wMinute;
! tm.tm_hour = st_localtz.wHour;
! tm.tm_mday = st_localtz.wDay;
! tm.tm_mon = st_localtz.wMonth - 1;
! tm.tm_year = st_localtz.wYear - 1900;
! tm.tm_wday = st_localtz.wDayOfWeek;
! tm.tm_yday = -1;
! tm.tm_isdst = -1;
! return mktime(&tm);
! } /* FileTimeToTimeT */
!
! PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname)
! {
! WIN32_FILE_ATTRIBUTE_DATA AttributeData;
!
! GetFileAttributesEx(fname, GetFileExInfoStandard, &AttributeData);
! /* 0 return value indicates an error or not supported */
! if(AttributeData.ftLastWriteTime.dwHighDateTime == 0 &&
! AttributeData.ftLastWriteTime.dwLowDateTime == 0)
! {
! /* Return error */
! BAIL_MACRO(win32strerror(), -1);
! }
!
! /* Return UNIX time_t version of last write time */
! return (PHYSFS_sint64)FileTimeToTimeT(&AttributeData.ftLastWriteTime);
! /*return (PHYSFS_sint64)FileTimeToTimeT(&AttributeData.ftCreationTime);*/
! } /* __PHYSFS_platformGetLastModTime */
/* end of win32.c ... */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [paragui-cvs] CVS: paragui/src/physfs/platform Makefile.am,1.1.1.1.6.1,1.1.1.1.6.2 macclassic.c,1.1.2.1,1.1.2.2 skeleton.c,1.1.2.1,1.1.2.2 unix.c,1.1.1.1.6.1,1.1.1.1.6.2 win32.c,1.1.1.1.6.8,1.1.1.1.6.9,
Alexander Pipelka <address@hidden> <=
- Prev by Date:
[paragui-cvs] CVS: paragui/src/physfs CHANGELOG,1.1.1.1,1.1.1.1.6.1 INSTALL,1.1.1.1,1.1.1.1.6.1 Makefile.am,1.1.1.1.6.1,1.1.1.1.6.2 TODO,1.1.1.1,1.1.1.1.6.1 physfs.c,1.1.1.1.6.2,1.1.1.1.6.3 physfs.h,1.1.1.1.6.1,1.1.1.1.6.2 physfs_byteorder.c,1.1.2.1,1.1.2.2 physfs_internal.h,1.1.1.1.6.1,1.1.1.1.6.2
- Next by Date:
[paragui-cvs] CVS: paragui/src/physfs CREDITS,NONE,1.1.2.1 CWProjects.sit,NONE,1.1.2.1 Doxyfile,NONE,1.1.2.1 configure.in,NONE,1.1.2.1 physfs.dsp,NONE,1.1.2.1 test_physfs.dsp,NONE,1.1.2.1
- Previous by thread:
[paragui-cvs] CVS: paragui/src/physfs CHANGELOG,1.1.1.1,1.1.1.1.6.1 INSTALL,1.1.1.1,1.1.1.1.6.1 Makefile.am,1.1.1.1.6.1,1.1.1.1.6.2 TODO,1.1.1.1,1.1.1.1.6.1 physfs.c,1.1.1.1.6.2,1.1.1.1.6.3 physfs.h,1.1.1.1.6.1,1.1.1.1.6.2 physfs_byteorder.c,1.1.2.1,1.1.2.2 physfs_internal.h,1.1.1.1.6.1,1.1.1.1.6.2
- Next by thread:
[paragui-cvs] CVS: paragui/src/physfs CREDITS,NONE,1.1.2.1 CWProjects.sit,NONE,1.1.2.1 Doxyfile,NONE,1.1.2.1 configure.in,NONE,1.1.2.1 physfs.dsp,NONE,1.1.2.1 test_physfs.dsp,NONE,1.1.2.1
- Index(es):