Changeset 157 in libcf
- Timestamp:
- 11/26/13 09:06:48 (10 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/cf_file.c
r154 r157 234 234 CF_File_GetSize (const char * path) 235 235 { 236 int length = 0;237 236 int result = 0; 238 237 … … 241 240 ASSERT_ARGS (path == NULL); 242 241 243 result = CF_File_Open ((cf_ctx *)&context, path, CF_FILE_READ); 244 if (result < 0) 245 return CF_ERROR_FILE_OPEN; 246 247 length = (int) lseek (context->fd, 0, SEEK_END); 248 if (length < 0) 249 return CF_ERROR_FILE_GET_SIZE; 242 TRY 243 { 244 result = CF_File_Open ((cf_ctx *)&context, path, CF_FILE_READ); 245 if (result < 0) 246 { 247 result = CF_ERROR_FILE_OPEN; 248 TRY_BREAK; 249 } 250 251 result = (int) lseek (context->fd, 0, SEEK_END); 252 if (result < 0) 253 { 254 result = CF_ERROR_FILE_GET_SIZE; 255 TRY_BREAK; 256 } 257 } 258 NO_CATCH; 250 259 251 260 CF_File_Close ((cf_ctx)context); 252 261 253 return length;262 return result; 254 263 } 255 264 … … 287 296 ASSERT_ARGS (path == NULL); 288 297 289 length = strlen (path); 290 fullpath = (char *) calloc (length + 2, 1); 291 if (!fullpath) 292 return CF_ERROR_FILE_ALLOCATE_BUFFER; 293 294 f = fullpath; 295 d = stepPath; 296 297 snprintf (fullpath, length + 1, "%s%c", path, DELIMITER); 298 299 for (*d++ = *f++ ; *f ; *d++ = *f++) 298 TRY 300 299 { 301 if (*f != DELIMITER) 302 continue; 303 304 if (CF_File_Exists (stepPath)) 305 continue; 300 length = strlen (path); 301 fullpath = (char *) calloc (length + 2, 1); 302 if (!fullpath) 303 { 304 result = CF_ERROR_FILE_ALLOCATE_BUFFER; 305 TRY_BREAK; 306 } 307 308 f = fullpath; 309 d = stepPath; 310 311 snprintf (fullpath, length + 1, "%s%c", path, DELIMITER); 312 313 for (*d++ = *f++ ; *f ; *d++ = *f++) 314 { 315 if (*f != DELIMITER) 316 continue; 317 318 if (CF_File_Exists (stepPath)) 319 continue; 306 320 307 321 #define DIRECTORY_MODE (S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH) 308 result = mkdir (stepPath, DIRECTORY_MODE); 309 if (result && errno != EEXIST) 310 return CF_ERROR_FILE_MAKE_DIRECTORY; 322 result = mkdir (stepPath, DIRECTORY_MODE); 323 if (result && errno != EEXIST) 324 { 325 result = CF_ERROR_FILE_MAKE_DIRECTORY; 326 break; 327 } 328 } 311 329 } 312 313 return CF_OK; 330 NO_CATCH; 331 332 if (fullpath) free (fullpath); 333 334 return result; 314 335 } 315 336 -
trunk/src/cf_log.c
r155 r157 45 45 typedef struct __cf_log_ctx__ 46 46 { 47 cf_ctx 48 char 49 size_t 50 size_t 47 cf_ctx file; 48 char * buffer; 49 size_t size; /* entire size of buffer */ 50 size_t length; /* data length in current */ 51 51 cf_ctx mutex; 52 52 } CF_LOG_CONTEXT; -
trunk/test/log.c
r151 r157 47 47 48 48 /* initialize */ 49 /* single thread {{{ */ 49 50 if (CF_Log_Create (&globalLog, "log.txt", CF_LOG_NO_BUFFER) < 0) 50 51 CF_DEBUG_PRINT (stderr, "failed to open log\n"); … … 56 57 CF_DEBUG_PRINT (stderr, "failed to write log %d\n", result); 57 58 } 59 60 CF_Log_Destroy (globalLog); 61 /* }}} single thread */ 58 62 59 63 /* mt {{{ */
Note:
See TracChangeset
for help on using the changeset viewer.