Changeset 3612 in MondoRescue
- Timestamp:
- Nov 18, 2016, 5:31:40 PM (8 years ago)
- Location:
- branches/3.2/mondo/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mondo/src/include/mr_file.h
r2208 r3612 21 21 #define mr_fclose(x) mr_fclose_int((FILE **)&x, __LINE__,__FILE__) 22 22 #define mr_mkdir(x,y) mr_mkdir_int((const char *)x,(mode_t)y,__LINE__,__FILE__) 23 #define mr_getcwd() mr_getcwd_int(__LINE__,__FILE__) 23 24 24 25 extern FILE *mr_fopen_int(const char *path, const char *mode,int line, char *file); … … 26 27 extern void mr_fclose_int(FILE **fd, int line, char *file); 27 28 extern void mr_mkdir_int(const char *pathname, mode_t mode, int line, char *file); 29 extern char *mr_mkdir_int(int line, char *file); 28 30 29 31 #endif /* MR_FILE_H */ -
branches/3.2/mondo/src/lib/mr_file.c
r3509 r3612 13 13 #include <sys/types.h> 14 14 #include <sys/stat.h> 15 #include <stdlib.h> 16 #include <errno.h> 17 #include <unistd.h> 15 18 16 19 #include "mr_err.h" … … 68 71 } 69 72 } 73 74 /* Version of getcwd using dynamically allocated memory. Cf: man 3p getcwd */ 75 char *mr_getcwd_int(int line, char *file) { 76 77 long path_max; 78 size_t size; 79 char *buf; 80 char *ptr; 81 82 path_max = pathconf(".", _PC_PATH_MAX); 83 if (path_max == -1) { 84 size = (size_t)512; 85 } else if (path_max > 10240) { 86 size = (size_t)10240; 87 } else { 88 size = (size_t)path_max; 89 } 90 91 for (buf = ptr = NULL; ptr == NULL; size *= 2) { 92 if ((buf = realloc(buf, size)) == NULL) { 93 mr_msg_int(1,line,file,"mr_getcwd","Unable to realloc memory"); 94 mr_exit(-1,"Exiting"); 95 } 96 97 ptr = getcwd(buf, size); 98 if (ptr == NULL && errno != ERANGE) { 99 mr_msg_int(1,line,file,"mr_getcwd","Unable to get current working directory"); 100 mr_exit(-1,"Exiting"); 101 } 102 return(buf); 103 } 104 }
Note:
See TracChangeset
for help on using the changeset viewer.