Main Page   Data Structures   File List   Data Fields   Globals   Related Pages  

nix-common/nix_utils.c

Go to the documentation of this file.
00001 
00005 #include <zakdef.h>
00006 #include <unistd.h>
00007 #include <sys/stat.h>
00008 #include <stdio.h>
00009 #include <stdlib.h>
00010 #include <string.h>
00011 #include <errno.h>
00012 #include <strings.h>
00013 #include <nix_utils.h>
00014 
00015 int
00016 searchForFile(Char *file, UInt16 length, Char *path)
00017 {
00018         char *buffer;
00019         char *atp = strdup(path);
00020         char *tat = atp;
00021         char *cap;
00022         struct stat sbuf;
00023         size_t max_path = pathconf("/", _PC_PATH_MAX);
00024 
00025         buffer = malloc(max_path + 1);
00026 
00027         do {
00028                 cap = strchr(atp, ':');
00029                 if (cap != NULL)
00030                         *cap = '\0';
00031                 snprintf(buffer, max_path, "%s/%s", atp, file);
00032                 if (stat(buffer, &sbuf) != -1) {
00033                         strlcpy(file, buffer, length);
00034                         free(tat);
00035                         free(buffer);
00036                         return (1);
00037                 }
00038                 if (cap != NULL)
00039                         atp = cap + 1;
00040         } while (cap != NULL);
00041         if (tat != NULL) free(tat);
00042         free(buffer);
00043         return (0);
00044 }
00045 

Generated on Mon Aug 30 19:44:15 2004 for pocketcity by doxygen1.2.18