- Timestamp:
- Feb 25, 2019, 1:57:11 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/prototype-v0/zoo-project/zoo-kernel/service_internal.c
r890 r896 917 917 } 918 918 919 /** 920 * Check if file exists in specified folder 921 * 922 * @param dir the folder in which to search for file 923 * @param name the name of the file (not full path) 924 * @return a character string with the full path [dir/name], or NULL if the file does not exist 925 * 926 * @attention Caller is responsible for applying free() to the returned pointer 927 */ 928 char* file_exists(const char* dir, const char* name) { 929 char* d = (dir != NULL ? dir : "."); 930 if (name != NULL) { 931 size_t length = strlen(d) + strlen(name) + 2; // including file separator and \0 character 932 char* path = (char*)calloc(length, sizeof(char)); 933 snprintf(path, length, "%s/%s", d, name); 934 935 struct stat buffer; 936 if (stat(path, &buffer) != 0) { 937 free(path); 938 path = NULL; 939 } 940 return path; 941 } 942 else { 943 return NULL; 944 } 945 }
Note: See TracChangeset
for help on using the changeset viewer.