Changeset 41 in libcf
- Timestamp:
- 02/07/13 10:18:02 (11 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/cf_error.h
r40 r41 17 17 #define CF_ERROR_FILE_CLOSE CF_ERROR_FILE - 6 18 18 #define CF_ERROR_FILE_GET_SIZE CF_ERROR_FILE - 7 19 #define CF_ERROR_FILE_MAKE_DIRECTORY CF_ERROR_FILE - 8 19 20 20 21 /* }}} socket */ -
trunk/include/cf_file.h
r40 r41 49 49 CF_File_GetSize (const int fd); 50 50 51 CF_EXPORT int 52 CF_File_MakeDirectory (const char * path); 53 51 54 #ifdef __cplusplus 52 55 } -
trunk/src/cf_file.c
r40 r41 7 7 #include "cf_error.h" 8 8 9 #include <stdio.h> 10 #include <errno.h> 11 #include <sys/stat.h> 12 9 13 #ifdef _WIN32 10 # include <stdio.h>11 14 # include <io.h> 12 # include <sys/stat.h> 13 15 # include <direct.h> 16 17 # define DELIMITER '\\' 18 # define mkdir(a,b) _mkdir (a) 19 # define access(a,b) _access (a,b) 20 21 /*------------------------------*/ 14 22 # define S_IWUSR _S_IWRITE 15 23 # define S_IRUSR _S_IREAD 16 24 # define S_IXUSR _S_IEXEC 25 /*------------------------------*/ 17 26 # define S_IRGRP 0x00000000 18 27 # define S_IWGRP 0x00000000 19 28 # define S_IXGRP 0x00000000 29 /*------------------------------*/ 20 30 # define S_IROTH 0x00000000 21 31 # define S_IWOTH 0x00000000 22 32 # define S_IXOTH 0x00000000 33 /*------------------------------*/ 34 # define S_IRWXU 0x00000000 23 35 #else // #ifdef _WIN32 24 36 # include <unistd.h> 37 38 # define DELIMITER '/' 25 39 # define O_BINARY 0x00000000 26 40 #endif // #ifdef _WIN32 27 41 28 #define FILE_MODE S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH 42 #define DIRECTORY_MODE S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH 43 #define FILE_MODE S_IWUSR|S_IRUSR|S_IRGRP|S_IROTH 29 44 30 45 /** … … 55 70 * @return 성공 시, 파일 디스크립터; 실패 시, 오류 코드 56 71 * 57 * @param path 72 * @param path 파일 경로 58 73 */ 59 74 int … … 140 155 * @return 성공 시, 파일 크기; 실패 시, 오류 코드 141 156 * 142 * @param fd 157 * @param fd 파일 디스크립터 143 158 */ 144 159 int … … 152 167 return result; 153 168 } 169 170 /** 171 * 디렉터리 생성 172 * 173 * @return 성공 시, CF_OK; 실패 시, 오류 코드 174 * 175 * @param path 생성할 디렉터리 경로 176 */ 177 int 178 CF_File_MakeDirectory (const char * path) 179 { 180 int result = 0; 181 char fullPath[1024] = {0x00,}; 182 char stepPath[256] = {0x00,}; 183 184 char * f = fullPath; 185 char * d = stepPath; 186 187 sprintf (fullPath, "%s%c", path, DELIMITER); 188 189 for (*d++ = *f++ ; *f ; *d++ = *f++) 190 { 191 if (*f != DELIMITER) 192 continue; 193 194 if (access (stepPath, F_OK) == 0) 195 continue; 196 197 result = mkdir (stepPath, DIRECTORY_MODE); 198 if (result && errno != EEXIST) 199 return CF_ERROR_FILE_MAKE_DIRECTORY; 200 } 201 202 return CF_OK; 203 } -
trunk/test/file.c
r35 r41 9 9 int main (void) { 10 10 int fd = 0; 11 char *dir1 = "./dir1/test"; 12 char *dir2 = "dir2/test"; 11 13 char *name = "file.txt"; 12 14 char buffer[128] = {0x00,}; 15 16 if (CF_File_MakeDirectory (dir1)) { 17 // error 18 } 19 20 if (CF_File_MakeDirectory (dir2)) { 21 // error 22 } 13 23 14 24 fd = CF_File_Create (name);
Note:
See TracChangeset
for help on using the changeset viewer.