summaryrefslogtreecommitdiff
path: root/legacy/ecore/src/lib/ecore_file/ecore_file.c
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2010-06-10 11:57:12 +0000
committerCedric BAIL <cedric.bail@free.fr>2010-06-10 11:57:12 +0000
commit238b9836ca2479583d30645304000983358602a7 (patch)
tree3f072a22c5ae3fb05ff520b5cbfaebf72dd98e79 /legacy/ecore/src/lib/ecore_file/ecore_file.c
parentddb8c95fa994ffc95758044d317879be46da3625 (diff)
* ecore: return Eina_Bool instead of int when it make sense.
Patch from Nicolas Aguirre. SVN revision: 49611
Diffstat (limited to '')
-rw-r--r--legacy/ecore/src/lib/ecore_file/ecore_file.c141
1 files changed, 72 insertions, 69 deletions
diff --git a/legacy/ecore/src/lib/ecore_file/ecore_file.c b/legacy/ecore/src/lib/ecore_file/ecore_file.c
index 385307a11b..8435c45ccc 100644
--- a/legacy/ecore/src/lib/ecore_file/ecore_file.c
+++ b/legacy/ecore/src/lib/ecore_file/ecore_file.c
@@ -126,31 +126,31 @@ ecore_file_size(const char *file)
126/** 126/**
127 * Check if file exists 127 * Check if file exists
128 * @param file The name of the file 128 * @param file The name of the file
129 * @return 1 if file exists on local filesystem, 0 otherwise 129 * @return EINA_TRUE if file exists on local filesystem, EINA_FALSE otherwise
130 */ 130 */
131EAPI int 131EAPI Eina_Bool
132ecore_file_exists(const char *file) 132ecore_file_exists(const char *file)
133{ 133{
134 struct stat st; 134 struct stat st;
135 135
136 /*Workaround so that "/" returns a true, otherwise we can't monitor "/" in ecore_file_monitor*/ 136 /*Workaround so that "/" returns a true, otherwise we can't monitor "/" in ecore_file_monitor*/
137 if (stat(file, &st) < 0 && strcmp(file, "/")) return 0; 137 if (stat(file, &st) < 0 && strcmp(file, "/")) return EINA_FALSE;
138 return 1; 138 return EINA_TRUE;
139} 139}
140 140
141/** 141/**
142 * Check if file is a directory 142 * Check if file is a directory
143 * @param file The name of the file 143 * @param file The name of the file
144 * @return 1 if file exist and is a directory, 0 otherwise 144 * @return EINA_TRUE if file exist and is a directory, EINA_FALSE otherwise
145 */ 145 */
146EAPI int 146EAPI Eina_Bool
147ecore_file_is_dir(const char *file) 147ecore_file_is_dir(const char *file)
148{ 148{
149 struct stat st; 149 struct stat st;
150 150
151 if (stat(file, &st) < 0) return 0; 151 if (stat(file, &st) < 0) return EINA_FALSE;
152 if (S_ISDIR(st.st_mode)) return 1; 152 if (S_ISDIR(st.st_mode)) return EINA_TRUE;
153 return 0; 153 return EINA_FALSE;
154} 154}
155 155
156static mode_t default_mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; 156static mode_t default_mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
@@ -158,15 +158,15 @@ static mode_t default_mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S
158/** 158/**
159 * Create a new directory 159 * Create a new directory
160 * @param dir The name of the directory to create 160 * @param dir The name of the directory to create
161 * @return 1 on successfull creation, 0 on failure 161 * @return EINA_TRUE on successfull creation, EINA_FALSE on failure
162 * 162 *
163 * The directory is created with the mode: S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH 163 * The directory is created with the mode: S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH
164 */ 164 */
165EAPI int 165EAPI Eina_Bool
166ecore_file_mkdir(const char *dir) 166ecore_file_mkdir(const char *dir)
167{ 167{
168 if (mkdir(dir, default_mode) < 0) return 0; 168 if (mkdir(dir, default_mode) < 0) return EINA_FALSE;
169 return 1; 169 return EINA_TRUE;
170} 170}
171 171
172/** 172/**
@@ -285,47 +285,47 @@ ecore_file_mksubdirs(const char *base, const char **subdirs)
285/** 285/**
286 * Delete the given dir 286 * Delete the given dir
287 * @param dir The name of the directory to delete 287 * @param dir The name of the directory to delete
288 * @return 1 on success, 0 on failure 288 * @return EINA_TRUE on success, EINA_FALSE on failure
289 */ 289 */
290EAPI int 290EAPI Eina_Bool
291ecore_file_rmdir(const char *dir) 291ecore_file_rmdir(const char *dir)
292{ 292{
293 if (rmdir(dir) < 0) return 0; 293 if (rmdir(dir) < 0) return EINA_FALSE;
294 return 1; 294 return EINA_TRUE;
295} 295}
296 296
297/** 297/**
298 * Delete the given file 298 * Delete the given file
299 * @param file The name of the file to delete 299 * @param file The name of the file to delete
300 * @return 1 on success, 0 on failure 300 * @return EINA_TRUE on success, EINA_FALSE on failure
301 */ 301 */
302EAPI int 302EAPI Eina_Bool
303ecore_file_unlink(const char *file) 303ecore_file_unlink(const char *file)
304{ 304{
305 if (unlink(file) < 0) return 0; 305 if (unlink(file) < 0) return EINA_FALSE;
306 return 1; 306 return EINA_TRUE;
307} 307}
308 308
309/** 309/**
310 * Remove the given file or directory 310 * Remove the given file or directory
311 * @param file The name of the file or directory to delete 311 * @param file The name of the file or directory to delete
312 * @return 1 on success, 0 on failure 312 * @return EINA_TRUE on success, EINA_FALSE on failure
313 */ 313 */
314EAPI int 314EAPI Eina_Bool
315ecore_file_remove(const char *file) 315ecore_file_remove(const char *file)
316{ 316{
317 if (remove(file) < 0) return 0; 317 if (remove(file) < 0) return EINA_FALSE;
318 return 1; 318 return EINA_TRUE;
319} 319}
320 320
321/** 321/**
322 * Delete a directory and all its contents 322 * Delete a directory and all its contents
323 * @param dir The name of the directory to delete 323 * @param dir The name of the directory to delete
324 * @return 1 on success, 0 on failure 324 * @return EINA_TRUE on success, EINA_FALSE on failure
325 * 325 *
326 * If dir is a link only the link is removed 326 * If dir is a link only the link is removed
327 */ 327 */
328EAPI int 328EAPI Eina_Bool
329ecore_file_recursive_rm(const char *dir) 329ecore_file_recursive_rm(const char *dir)
330{ 330{
331 DIR *dirp; 331 DIR *dirp;
@@ -341,7 +341,7 @@ ecore_file_recursive_rm(const char *dir)
341 if ((ret == 0) && (S_ISDIR(st.st_mode))) 341 if ((ret == 0) && (S_ISDIR(st.st_mode)))
342 { 342 {
343 ret = 1; 343 ret = 1;
344 if (stat(dir, &st) == -1) return 0; 344 if (stat(dir, &st) == -1) return EINA_FALSE;
345 dirp = opendir(dir); 345 dirp = opendir(dir);
346 if (dirp) 346 if (dirp)
347 { 347 {
@@ -357,16 +357,19 @@ ecore_file_recursive_rm(const char *dir)
357 closedir(dirp); 357 closedir(dirp);
358 } 358 }
359 if (!ecore_file_rmdir(dir)) ret = 0; 359 if (!ecore_file_rmdir(dir)) ret = 0;
360 return ret; 360 if (ret)
361 return EINA_TRUE;
362 else
363 return EINA_FALSE;
361 } 364 }
362 else 365 else
363 { 366 {
364 if (ret == -1) return 0; 367 if (ret == -1) return EINA_FALSE;
365 return ecore_file_unlink(dir); 368 return ecore_file_unlink(dir);
366 } 369 }
367} 370}
368 371
369static inline int 372static inline Eina_Bool
370_ecore_file_mkpath_if_not_exists(const char *path) 373_ecore_file_mkpath_if_not_exists(const char *path)
371{ 374{
372 struct stat st; 375 struct stat st;
@@ -374,35 +377,35 @@ _ecore_file_mkpath_if_not_exists(const char *path)
374 if (stat(path, &st) < 0) 377 if (stat(path, &st) < 0)
375 return ecore_file_mkdir(path); 378 return ecore_file_mkdir(path);
376 else if (!S_ISDIR(st.st_mode)) 379 else if (!S_ISDIR(st.st_mode))
377 return 0; 380 return EINA_FALSE;
378 else 381 else
379 return 1; 382 return EINA_TRUE;
380} 383}
381 384
382/** 385/**
383 * Create a complete path 386 * Create a complete path
384 * @param path The path to create 387 * @param path The path to create
385 * @return 1 on success, 0 on failure 388 * @return EINA_TRUE on success, EINA_FALSE on failure
386 * 389 *
387 * @see ecore_file_mkpaths() and ecore_file_mkdir() 390 * @see ecore_file_mkpaths() and ecore_file_mkdir()
388 */ 391 */
389EAPI int 392EAPI Eina_Bool
390ecore_file_mkpath(const char *path) 393ecore_file_mkpath(const char *path)
391{ 394{
392 char ss[PATH_MAX]; 395 char ss[PATH_MAX];
393 unsigned int i; 396 unsigned int i;
394 397
395 if (ecore_file_is_dir(path)) 398 if (ecore_file_is_dir(path))
396 return 1; 399 return EINA_TRUE;
397 400
398 for (i = 0; path[i] != '\0'; ss[i] = path[i], i++) 401 for (i = 0; path[i] != '\0'; ss[i] = path[i], i++)
399 { 402 {
400 if (i == sizeof(ss) - 1) return 0; 403 if (i == sizeof(ss) - 1) return EINA_FALSE;
401 if ((path[i] == '/') && (i > 0)) 404 if ((path[i] == '/') && (i > 0))
402 { 405 {
403 ss[i] = '\0'; 406 ss[i] = '\0';
404 if (!_ecore_file_mkpath_if_not_exists(ss)) 407 if (!_ecore_file_mkpath_if_not_exists(ss))
405 return 0; 408 return EINA_FALSE;
406 } 409 }
407 } 410 }
408 ss[i] = '\0'; 411 ss[i] = '\0';
@@ -434,31 +437,31 @@ ecore_file_mkpaths(const char **paths)
434 * Copy a file 437 * Copy a file
435 * @param src The name of the source file 438 * @param src The name of the source file
436 * @param dst The name of the destination file 439 * @param dst The name of the destination file
437 * @return 1 on success, 0 on failure 440 * @return EINA_TRUE on success, EINA_FALSE on failure
438 */ 441 */
439EAPI int 442EAPI Eina_Bool
440ecore_file_cp(const char *src, const char *dst) 443ecore_file_cp(const char *src, const char *dst)
441{ 444{
442 FILE *f1, *f2; 445 FILE *f1, *f2;
443 char buf[16384]; 446 char buf[16384];
444 char realpath1[PATH_MAX], realpath2[PATH_MAX]; 447 char realpath1[PATH_MAX], realpath2[PATH_MAX];
445 size_t num; 448 size_t num;
446 int ret = 1; 449 Eina_Bool ret = EINA_TRUE;
447 450
448 if (!realpath(src, realpath1)) return 0; 451 if (!realpath(src, realpath1)) return EINA_FALSE;
449 if (realpath(dst, realpath2) && !strcmp(realpath1, realpath2)) return 0; 452 if (realpath(dst, realpath2) && !strcmp(realpath1, realpath2)) return EINA_FALSE;
450 453
451 f1 = fopen(src, "rb"); 454 f1 = fopen(src, "rb");
452 if (!f1) return 0; 455 if (!f1) return EINA_FALSE;
453 f2 = fopen(dst, "wb"); 456 f2 = fopen(dst, "wb");
454 if (!f2) 457 if (!f2)
455 { 458 {
456 fclose(f1); 459 fclose(f1);
457 return 0; 460 return EINA_FALSE;
458 } 461 }
459 while ((num = fread(buf, 1, sizeof(buf), f1)) > 0) 462 while ((num = fread(buf, 1, sizeof(buf), f1)) > 0)
460 { 463 {
461 if (fwrite(buf, 1, num, f2) != num) ret = 0; 464 if (fwrite(buf, 1, num, f2) != num) ret = EINA_FALSE;
462 } 465 }
463 fclose(f1); 466 fclose(f1);
464 fclose(f2); 467 fclose(f2);
@@ -469,9 +472,9 @@ ecore_file_cp(const char *src, const char *dst)
469 * Move a file 472 * Move a file
470 * @param src The name of the source file 473 * @param src The name of the source file
471 * @param dst The name of the destination file 474 * @param dst The name of the destination file
472 * @return 1 on success, 0 on failure 475 * @return EINA_TRUE on success, EINA_FALSE on failure
473 */ 476 */
474EAPI int 477EAPI Eina_Bool
475ecore_file_mv(const char *src, const char *dst) 478ecore_file_mv(const char *src, const char *dst)
476{ 479{
477 char buf[PATH_MAX]; 480 char buf[PATH_MAX];
@@ -533,24 +536,24 @@ ecore_file_mv(const char *src, const char *dst)
533 } 536 }
534 537
535PASS: 538PASS:
536 return 1; 539 return EINA_TRUE;
537 540
538FAIL: 541FAIL:
539 return 0; 542 return EINA_FALSE;
540} 543}
541 544
542/** 545/**
543 * Create a symbolic link 546 * Create a symbolic link
544 * @param src The name of the file to link 547 * @param src The name of the file to link
545 * @param dest The name of link 548 * @param dest The name of link
546 * @return 1 on success, 0 on failure 549 * @return EINA_TRUE on success, EINA_FALSE on failure
547 */ 550 */
548EAPI int 551EAPI Eina_Bool
549ecore_file_symlink(const char *src, const char *dest) 552ecore_file_symlink(const char *src, const char *dest)
550{ 553{
551 if (!symlink(src, dest)) return 1; 554 if (!symlink(src, dest)) return EINA_TRUE;
552 555
553 return 0; 556 return EINA_FALSE;
554} 557}
555 558
556/** 559/**
@@ -611,40 +614,40 @@ ecore_file_dir_get(const char *file)
611/** 614/**
612 * Check if file can be read 615 * Check if file can be read
613 * @param file The name of the file 616 * @param file The name of the file
614 * @return 1 if the file is readable, 0 otherwise 617 * @return EINA_TRUE if the file is readable, EINA_FALSE otherwise
615 */ 618 */
616EAPI int 619EAPI Eina_Bool
617ecore_file_can_read(const char *file) 620ecore_file_can_read(const char *file)
618{ 621{
619 if (!file) return 0; 622 if (!file) return EINA_FALSE;
620 if (!access(file, R_OK)) return 1; 623 if (!access(file, R_OK)) return EINA_TRUE;
621 return 0; 624 return EINA_FALSE;
622} 625}
623 626
624/** 627/**
625 * Check if file can be written 628 * Check if file can be written
626 * @param file The name of the file 629 * @param file The name of the file
627 * @return 1 if the file is writable, 0 otherwise 630 * @return EINA_TRUE if the file is writable, EINA_FALSE otherwise
628 */ 631 */
629EAPI int 632EAPI Eina_Bool
630ecore_file_can_write(const char *file) 633ecore_file_can_write(const char *file)
631{ 634{
632 if (!file) return 0; 635 if (!file) return EINA_FALSE;
633 if (!access(file, W_OK)) return 1; 636 if (!access(file, W_OK)) return EINA_TRUE;
634 return 0; 637 return EINA_FALSE;
635} 638}
636 639
637/** 640/**
638 * Check if file can be executed 641 * Check if file can be executed
639 * @param file The name of the file 642 * @param file The name of the file
640 * @return 1 if the file can be executed, 0 otherwise 643 * @return EINA_TRUE if the file can be executed, EINA_FALSE otherwise
641 */ 644 */
642EAPI int 645EAPI Eina_Bool
643ecore_file_can_exec(const char *file) 646ecore_file_can_exec(const char *file)
644{ 647{
645 if (!file) return 0; 648 if (!file) return EINA_FALSE;
646 if (!access(file, X_OK)) return 1; 649 if (!access(file, X_OK)) return EINA_TRUE;
647 return 0; 650 return EINA_FALSE;
648} 651}
649 652
650/** 653/**