Skip to content
Permalink
Browse files
FIXME removal.
  • Loading branch information
icculus committed May 21, 2002
1 parent 996aa00 commit 769b2a5464df93661e07092e63cc2a4425bc7352
Showing with 64 additions and 40 deletions.
  1. +1 −1 archivers/dir.c
  2. +1 −3 physfs.c
  3. +0 −6 physfs.h
  4. +62 −30 platform/unix.c
@@ -234,7 +234,7 @@ static int DIR_isSymLink(DirHandle *h, const char *name)
char *f = __PHYSFS_platformCvtToDependent((char *)(h->opaque), name, NULL);
int retval;

BAIL_IF_MACRO(f == NULL, NULL, 0); /* !!! might be a problem. */
BAIL_IF_MACRO(f == NULL, NULL, 0);
retval = __PHYSFS_platformIsSymLink(f);
free(f);
return(retval);
@@ -350,7 +350,7 @@ static char *calculateBaseDir(const char *argv0)
p = strstr(p + 1, dirsep);
} /* while */

size = (size_t) (ptr - argv0); /* !!! is this portable? */
size = (size_t) (ptr - argv0);
retval = (char *) malloc(size + 1);
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
memcpy(retval, argv0, size);
@@ -1202,8 +1202,6 @@ int PHYSFS_isSymbolicLink(const char *fname)
} /* if */
} /* if */
} /* for */

/* !!! FIXME: setError ERR_FILE_NOT_FOUND? */
__PHYSFS_platformReleaseMutex(stateLock);

return(0);
@@ -978,12 +978,6 @@ __EXPORT__ PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 val);
*/
__EXPORT__ PHYSFS_uint64 PHYSFS_swapUBE64(PHYSFS_uint64 val);



#if 0 /* !!! FIXME: add this? */
#undef __EXPORT__
#endif

#ifdef __cplusplus
}
#endif
@@ -100,7 +100,8 @@ char **__PHYSFS_platformDetectAvailableCDs(void)
add_it = 1;
else if ( strcmp( mntbufp[ii].f_fstypename, "cd9660") == 0 )
add_it = 1;
/* !!! other mount types? */

/* add other mount types here */

if (add_it)
{
@@ -147,7 +148,8 @@ char **__PHYSFS_platformDetectAvailableCDs(void)
int add_it = 0;
if (strcmp(ent->mnt_type, "iso9660") == 0)
add_it = 1;
/* !!! other mount types? */

/* add other mount types here */

if (add_it)
{
@@ -190,52 +192,82 @@ static char *copyEnvironmentVariable(const char *varname)
} /* copyEnvironmentVariable */


/* !!! this is ugly. */
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
/*
* 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)
{
/* If there isn't a path on argv0, then look through the $PATH for it. */

char *retval = NULL;
char *envr;
char *start;
size_t alloc_size = 0;
char *exe = NULL;
char *start = envr;
char *ptr;
char *exe;

if (strchr(argv0, '/') != NULL) /* default behaviour can handle this. */
return(NULL);

envr = copyEnvironmentVariable("PATH");
BAIL_IF_MACRO(!envr, NULL, NULL);
BAIL_IF_MACRO(bin == NULL, ERR_INVALID_ARGUMENT, NULL);
BAIL_IF_MACRO(envr == NULL, ERR_INVALID_ARGUMENT, NULL);

start = envr;
do
{
ptr = strchr(start, ':');
size_t size;
ptr = strchr(start, ':'); /* find next $PATH separator. */
if (ptr)
*ptr = '\0';

exe = (char *) malloc(strlen(start) + strlen(argv0) + 2);
if (!exe)
size = strlen(start) + strlen(bin) + 2;
if (size > alloc_size)
{
free(envr);
BAIL_IF_MACRO(1, ERR_OUT_OF_MEMORY, NULL);
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, argv0);
if (access(exe, X_OK) != 0)
free(exe);
else
strcat(exe, bin);

if (access(exe, X_OK) == 0) /* Exists as executable? We're done. */
{
retval = exe;
strcpy(retval, start); /* i'm lazy. piss off. */
break;
} /* else */
strcpy(exe, start); /* i'm lazy. piss off. */
return(exe);
} /* if */

start = ptr + 1;
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 = copyEnvironmentVariable("PATH");
BAIL_IF_MACRO(!envr, NULL, NULL);
retval = findBinaryInPath(argv0, envr);
free(envr);
return(retval);
} /* __PHYSFS_platformCalcBaseDir */

0 comments on commit 769b2a5

Please sign in to comment.