[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Draft pkgdatadir_r(filename) relocation function.
From: |
John McCabe-Dansted |
Subject: |
Draft pkgdatadir_r(filename) relocation function. |
Date: |
Mon, 19 Feb 2007 13:56:22 +0900 |
Hi, I bashed out this code on the bus. What do you think of the style?
* Should I replace the calls the vasnprintf with calls to
xmalloc,strlen and strcat?
* should
static fn_full_data_dir=NULL;
be
static fn_full_data_dir[PATH_MAX];
BTW, PATH_MAX is only a soft limit on Windows NT onwards. Paths of
length 4096 and possibly more are supported.
---
/* a stub so the test harness compiles on linux, at least */
#define PKGDATADIR "/usr/share"
/* header */
#if defined _WIN32 || defined __WIN32__
#define PKGDATADIR_R(s) (pkgdatadir_r(s))
#else
#define PKGDATADIR_R(s) (PKGDATADIR s)
#endif
/* C-code */
#if defined _WIN32 || defined __WIN32__
static fn_full_data_dir=NULL;
static static_fullpath=NULL;
void set_prefix_from_argv0(const char *argv0) {
char *bin_dir;
char *data_dir;
char full_data_dir[PATH_MAX];
bin_dir=dir_name(argv0);
data_dir=xvasprintf("%s%s",bin_dir,"..\\share");
free(bin_dir);
if (GetFullPathName(data_dir,PATH_MAX,full_data_dir,NULL))
fn_full_data_dir=xstrcpy(full_data_dir);
else
fn_full_data_dir=xstrcpy(data_dir);
free(data_dir);
}
char* pkgdatadir_r(const char *filename)
{
ASSERT(fn_full_data_dir!=NULL);
if (static_fullpath!=NULL)
free(static_fullpath);
static_fullpath=xvasprintf("%s%s",fn_full_data_dir,filename);
return (static_fullpath);
}
#endif /*defined _WIN32 || defined __WIN32__*/
/* test harness */
int main(int argc, char **argv) {
#if defined _WIN32 || defined __WIN32__
set_prefix_from_argv0(argv[0]);
#endif
puts(PKGDATADIR_R("/testfile.txt"));
return 0;
}
--
John C. McCabe-Dansted
PhD Student
University of Western Australia
- Draft pkgdatadir_r(filename) relocation function.,
John McCabe-Dansted <=