summaryrefslogtreecommitdiff
path: root/legacy
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2011-09-15 13:57:27 +0000
committerCedric BAIL <cedric.bail@free.fr>2011-09-15 13:57:27 +0000
commit286252b18ae24d6956cba95d4426ad7a0dc1c102 (patch)
tree02bd0a2f92999269aa13d4fe7ff6d5ce11eaeb00 /legacy
parent680170b3f9aaec340ba38587ea1ba5919e61555e (diff)
eina: use eina safety check in eina_file.c.
SVN revision: 63409
Diffstat (limited to 'legacy')
-rw-r--r--legacy/eina/src/lib/eina_file.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/legacy/eina/src/lib/eina_file.c b/legacy/eina/src/lib/eina_file.c
index fd76dd1c3e..2c7a6dcc47 100644
--- a/legacy/eina/src/lib/eina_file.c
+++ b/legacy/eina/src/lib/eina_file.c
@@ -643,8 +643,7 @@ eina_file_ls(const char *dir)
643 Eina_File_Iterator *it; 643 Eina_File_Iterator *it;
644 size_t length; 644 size_t length;
645 645
646 if (!dir) 646 EINA_SAFETY_ON_NULL_RETURN_VAL(dir, NULL);
647 return NULL;
648 647
649 length = strlen(dir); 648 length = strlen(dir);
650 if (length < 1) 649 if (length < 1)
@@ -684,8 +683,7 @@ eina_file_direct_ls(const char *dir)
684 Eina_File_Direct_Iterator *it; 683 Eina_File_Direct_Iterator *it;
685 size_t length; 684 size_t length;
686 685
687 if (!dir) 686 EINA_SAFETY_ON_NULL_RETURN_VAL(dir, NULL);
688 return NULL;
689 687
690 length = strlen(dir); 688 length = strlen(dir);
691 if (length < 1) 689 if (length < 1)
@@ -734,8 +732,7 @@ eina_file_stat_ls(const char *dir)
734 Eina_File_Direct_Iterator *it; 732 Eina_File_Direct_Iterator *it;
735 size_t length; 733 size_t length;
736 734
737 if (!dir) 735 EINA_SAFETY_ON_NULL_RETURN_VAL(dir, NULL);
738 return NULL;
739 736
740 length = strlen(dir); 737 length = strlen(dir);
741 if (length < 1) 738 if (length < 1)
@@ -784,10 +781,9 @@ eina_xattr_ls(const char *file)
784 Eina_Xattr_Iterator *it; 781 Eina_Xattr_Iterator *it;
785 ssize_t length; 782 ssize_t length;
786 783
787#ifdef HAVE_XATTR 784 EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);
788 if (!file)
789 return NULL;
790 785
786#ifdef HAVE_XATTR
791 length = listxattr(file, NULL, 0); 787 length = listxattr(file, NULL, 0);
792 if (length <= 0) return NULL; 788 if (length <= 0) return NULL;
793 789
@@ -820,7 +816,10 @@ eina_xattr_get(const char *file, const char *attribute, ssize_t *size)
820 void *ret = NULL; 816 void *ret = NULL;
821 ssize_t tmp; 817 ssize_t tmp;
822 818
823 if (!size || !file || !attribute) return NULL; 819 EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);
820 EINA_SAFETY_ON_NULL_RETURN_VAL(attribute, NULL);
821 EINA_SAFETY_ON_TRUE_RETURN_VAL(!size, NULL);
822
824 *size = getxattr(file, attribute, NULL, 0); 823 *size = getxattr(file, attribute, NULL, 0);
825 /* Size should be less than 2MB (already huge in my opinion) */ 824 /* Size should be less than 2MB (already huge in my opinion) */
826 if (!(*size > 0 && *size < 2 * 1024 * 1024)) 825 if (!(*size > 0 && *size < 2 * 1024 * 1024))
@@ -846,8 +845,10 @@ eina_xattr_set(const char *file, const char *attribute, const void *data, ssize_
846{ 845{
847 int iflags; 846 int iflags;
848 847
849 if (!file || !attribute || !data || length <= 0 || length > 2 * 1024 * 1024) 848 EINA_SAFETY_ON_NULL_RETURN_VAL(file, EINA_FALSE);
850 return EINA_FALSE; 849 EINA_SAFETY_ON_NULL_RETURN_VAL(attribute, EINA_FALSE);
850 EINA_SAFETY_ON_NULL_RETURN_VAL(data, EINA_FALSE);
851 EINA_SAFETY_ON_TRUE_RETURN_VAL(!(length > 0 && length < 2 * 1024 * 1024), EINA_FALSE);
851 852
852 switch (flags) 853 switch (flags)
853 { 854 {
@@ -872,6 +873,8 @@ eina_file_open(const char *filename, Eina_Bool shared)
872 int fd; 873 int fd;
873 int flags; 874 int flags;
874 875
876 EINA_SAFETY_ON_NULL_RETURN_VAL(filename, NULL);
877
875 /* 878 /*
876 FIXME: always open absolute path 879 FIXME: always open absolute path
877 (need to fix filename according to current directory) 880 (need to fix filename according to current directory)
@@ -959,7 +962,8 @@ eina_file_open(const char *filename, Eina_Bool shared)
959EAPI void 962EAPI void
960eina_file_close(Eina_File *file) 963eina_file_close(Eina_File *file)
961{ 964{
962 if (!file) return; 965 EINA_SAFETY_ON_NULL_RETURN(file);
966
963 eina_lock_take(&file->lock); 967 eina_lock_take(&file->lock);
964 file->refcount--; 968 file->refcount--;
965 eina_lock_release(&file->lock); 969 eina_lock_release(&file->lock);
@@ -971,21 +975,21 @@ eina_file_close(Eina_File *file)
971EAPI size_t 975EAPI size_t
972eina_file_size_get(Eina_File *file) 976eina_file_size_get(Eina_File *file)
973{ 977{
974 if (!file) return 0; 978 EINA_SAFETY_ON_NULL_RETURN_VAL(file, 0);
975 return file->length; 979 return file->length;
976} 980}
977 981
978EAPI time_t 982EAPI time_t
979eina_file_mtime_get(Eina_File *file) 983eina_file_mtime_get(Eina_File *file)
980{ 984{
981 if (!file) return 0; 985 EINA_SAFETY_ON_NULL_RETURN_VAL(file, 0);
982 return file->mtime; 986 return file->mtime;
983} 987}
984 988
985EAPI const char * 989EAPI const char *
986eina_file_filename_get(Eina_File *file) 990eina_file_filename_get(Eina_File *file)
987{ 991{
988 if (!file) return NULL; 992 EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);
989 return file->filename; 993 return file->filename;
990} 994}
991 995
@@ -995,6 +999,8 @@ eina_file_map_all(Eina_File *file, Eina_File_Populate rule)
995 int flags = MAP_SHARED; 999 int flags = MAP_SHARED;
996 void *ret = NULL; 1000 void *ret = NULL;
997 1001
1002 EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);
1003
998// bsd people will lack this feature 1004// bsd people will lack this feature
999#ifdef MAP_POPULATE 1005#ifdef MAP_POPULATE
1000 if (rule == EINA_FILE_POPULATE) flags |= MAP_POPULATE; 1006 if (rule == EINA_FILE_POPULATE) flags |= MAP_POPULATE;
@@ -1087,6 +1093,8 @@ eina_file_map_new(Eina_File *file, Eina_File_Populate rule,
1087EAPI void 1093EAPI void
1088eina_file_map_free(Eina_File *file, void *map) 1094eina_file_map_free(Eina_File *file, void *map)
1089{ 1095{
1096 EINA_SAFETY_ON_NULL_RETURN(file);
1097
1090 eina_lock_take(&file->lock); 1098 eina_lock_take(&file->lock);
1091 1099
1092 if (file->global_map == map) 1100 if (file->global_map == map)