summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2011-01-06 18:26:40 +0000
committerVincent Torri <vincent.torri@gmail.com>2011-01-06 18:26:40 +0000
commit4ae06c2ccf9491279c36c04dbbff0fb7091bd1a6 (patch)
tree0fa81648cc9704f1244aa057bd39c2104e9c93bc
parentba9b4b0c87267680fb2a116778bc36c21151d793 (diff)
revert non wanted changes
SVN revision: 55939
-rw-r--r--src/lib/eina_cpu.c6
-rw-r--r--src/lib/eina_file.c278
2 files changed, 3 insertions, 281 deletions
diff --git a/src/lib/eina_cpu.c b/src/lib/eina_cpu.c
index 083ff5a..8af550d 100644
--- a/src/lib/eina_cpu.c
+++ b/src/lib/eina_cpu.c
@@ -162,11 +162,11 @@ EAPI int eina_cpu_count(void)
162 size_t len = sizeof(cpus); 162 size_t len = sizeof(cpus);
163 163
164 mib[0] = CTL_HW; 164 mib[0] = CTL_HW;
165# ifdef HW_AVAILCPU 165#ifdef HW_AVAILCPU
166 mib[1] = HW_AVAILCPU; 166 mib[1] = HW_AVAILCPU;
167# else 167#else
168 mib[1] = HW_NCPU; 168 mib[1] = HW_NCPU;
169# endif 169#endif
170 sysctl(mib, 2, &cpus, &len, NULL, 0); 170 sysctl(mib, 2, &cpus, &len, NULL, 0);
171 if (cpus < 1) 171 if (cpus < 1)
172 cpus = 1; 172 cpus = 1;
diff --git a/src/lib/eina_file.c b/src/lib/eina_file.c
index 5f0671b..08a8dd5 100644
--- a/src/lib/eina_file.c
+++ b/src/lib/eina_file.c
@@ -44,8 +44,6 @@ void *alloca (size_t);
44#include <sys/types.h> 44#include <sys/types.h>
45#include <sys/stat.h> 45#include <sys/stat.h>
46#include <unistd.h> 46#include <unistd.h>
47#include <fcntl.h>
48#include <sys/mman.h>
49 47
50#define PATH_DELIM '/' 48#define PATH_DELIM '/'
51 49
@@ -62,7 +60,6 @@ void *alloca (size_t);
62#include "eina_safety_checks.h" 60#include "eina_safety_checks.h"
63#include "eina_file.h" 61#include "eina_file.h"
64#include "eina_stringshare.h" 62#include "eina_stringshare.h"
65#include "eina_hash.h"
66 63
67/*============================================================================* 64/*============================================================================*
68 * Local * 65 * Local *
@@ -688,281 +685,6 @@ eina_file_stat_ls(const char *dir)
688 return &it->iterator; 685 return &it->iterator;
689} 686}
690 687
691
692/*
693 H : half
694 X : done
695
696 [ ] nom du fichier pour shm_open
697 [ ] stringshare pour le fichier
698 [H] flags dans des enum
699 [X] fstat pour la taille
700 [H] enregistrer dans un cache (hash) les fichiers ouverts
701 [ ] garder la liste des map ouvertes et les detruire
702 [X] mmap tout le fichier
703 [ ] hash pour les blocs mmap
704 [ ] taille de mmap : sauvegarder dans Eina_File
705 */
706
707#include "eina_log.h"
708
709static Eina_Hash *_eina_file_files = NULL;
710
711/* _eina_file_files = eina_hash_string_small_new(NULL) */
712
713typedef enum
714{
715 EINA_FILE_FLAG_READ = 0,
716 EINA_FILE_FLAG_WRITE = 1,
717 EINA_FILE_FLAG_READ_WRITE = 2,
718 EINA_FILE_FLAG_CREATE = 1 << 2,
719 EINA_FILE_FLAG_TRUNCATE = 1 << 3
720} Eina_File_Flag;
721
722typedef enum
723{
724 EINA_FILE_MODE_READ = 1 << 0,
725 EINA_FILE_MODE_WRITE = 1 << 1
726} Eina_File_Mode;
727
728typedef enum
729{
730 EINA_FILE_MAP_PROT_EXEC,
731 EINA_FILE_MAP_PROT_READ,
732 EINA_FILE_MAP_PROT_WRITE,
733 EINA_FILE_MAP_PROT_NONE
734} Eina_File_Map_Prot;
735
736typedef enum
737{
738 /* No MAP_FIXED, its use is discouraged */
739 EINA_FILE_MAP_FLAG_SHARED,
740 EINA_FILE_MAP_FLAG_PRIVATE
741} Eina_File_Map_Flag;
742
743typedef struct
744{
745 char *filename;
746 Eina_File_Flag flag;
747 Eina_File_Mode mode;
748 int fd;
749 off_t file_size;
750 off_t map_size;
751 void *map_full;
752 Eina_Hash *map_blocks;
753 Eina_Bool shared : 1;
754} Eina_File;
755
756static int _eina_file_log_dom = -1;
757
758#ifdef ERR
759#undef ERR
760#endif
761#define ERR(...) EINA_LOG_DOM_ERR(_eina_file_log_dom, __VA_ARGS__)
762
763Eina_Bool
764eina_file_init(void)
765{
766 _eina_file_log_dom = eina_log_domain_register("eina_file",
767 EINA_LOG_COLOR_DEFAULT);
768 if (_eina_file_log_dom < 0)
769 {
770 EINA_LOG_ERR("Could not register log domain: eina_file");
771 return EINA_FALSE;
772 }
773
774 return EINA_TRUE;
775}
776
777Eina_Bool
778eina_file_shutdown(void)
779{
780 eina_log_domain_unregister(_eina_file_log_dom);
781 _eina_file_log_dom = -1;
782 return EINA_TRUE;
783}
784
785EAPI Eina_File *
786eina_file_open(const char *filename, Eina_File_Flag flag, Eina_File_Mode mode, Eina_Bool shared)
787{
788 struct stat st;
789 Eina_File *file;
790 Eina_File *cache;
791 int oflag;
792 mode_t omode = 0;
793
794 if (!filename || !*filename) return NULL;
795
796 file = (Eina_File *)calloc(1, sizeof(Eina_File));
797 if (!file) return NULL;
798
799 if (shared)
800 {
801 size_t length;
802
803 length = strlen(filename) + 1;
804 file->filename = (char *)malloc(length + 1);
805 if (!file->filename) goto free_file;
806 *file->filename = '/';
807 memcpy(file->filename + 1, filename, length);
808 }
809 else
810 {
811 file->filename = strdup(filename);
812 if (!file->filename) goto free_file;
813 }
814
815 file->flag = flag;
816 file->mode = mode;
817 file->shared = shared;
818 switch (flag)
819 {
820 case EINA_FILE_FLAG_READ:
821 oflag = O_RDONLY;
822 break;
823 case EINA_FILE_FLAG_WRITE:
824 oflag = O_WRONLY;
825 break;
826 case EINA_FILE_FLAG_READ_WRITE:
827 oflag = O_RDWR;
828 break;
829 default:
830 oflag = O_RDONLY;
831 break;
832 }
833
834 if (flag & EINA_FILE_FLAG_CREATE) oflag |= O_CREAT;
835 if (flag & EINA_FILE_FLAG_TRUNCATE) oflag |= O_TRUNC;
836
837 if (mode & EINA_FILE_MODE_READ) omode |= S_IRUSR;
838 if (mode & EINA_FILE_MODE_WRITE) omode |= S_IWUSR;
839
840 if (shared)
841 {
842 file->fd = shm_open(file->filename, oflag, omode);
843 if (file->fd == -1)
844 goto free_filename;
845 }
846 else
847 {
848 file->fd = open(file->filename, oflag, omode);
849 if (file->fd == -1)
850 goto free_filename;
851 }
852
853 if (fstat(file->fd, &st) != 0)
854 {
855 ERR("Could not retrieve file size");
856 goto close_file;
857 }
858
859 file->file_size = st.st_size;
860
861 cache = eina_hash_find(_eina_file_files, file->filename);
862 if (cache)
863 {
864 /* faire plus de tests ? */
865 if (cache->file_size != file->file_size)
866 {
867 eina_hash_modify(_eina_file_files, file->filename, file);
868 free(cache->filename);
869 free(cache);
870 }
871 else
872 return cache;
873 }
874 else
875 eina_hash_add(_eina_file_files, file->filename, file);
876
877 return file;
878
879 close_file:
880 if (shared)
881 shm_unlink(file->filename);
882 else
883 close(file->fd);
884 free_filename:
885 free(file->filename);
886 free_file:
887 free(file);
888
889 return NULL;
890}
891
892EAPI void
893eina_file_close(Eina_File *file)
894{
895 if (!file)
896 return;
897
898 if (eina_hash_find(_eina_file_files, file->filename))
899 eina_hash_del(_eina_file_files, file->filename, file);
900
901 if (file->shared)
902 {
903 if (shm_unlink(file->filename) != 0)
904 ERR("Could not unlink %s", file->filename);
905 }
906 else
907 {
908 if (close(file->fd) != 0)
909 ERR("Could not close %s", file->filename);
910 }
911
912 free(file->filename);
913 free(file);
914}
915
916EAPI void *
917eina_file_map_full(Eina_File *file, Eina_File_Map_Prot prot, Eina_File_Map_Flag flags)
918{
919 if (!file || !file->shared)
920 return NULL;
921
922 if (!file->map_full)
923 {
924 file->map_size = file->file_size;
925 file->map_full = mmap(NULL, file->map_size, prot, flags, file->fd, 0);
926 }
927
928 return file->map_full;
929}
930
931EAPI Eina_Bool
932eina_file_unmap_full(Eina_File *file)
933{
934 if (!file || !file->map_full)
935 return EINA_FALSE;
936
937 return (munmap(file->map_full, file->map_size) == 0) ? EINA_TRUE : EINA_FALSE;
938}
939
940EAPI void *
941eina_file_map(Eina_File *file, void *start, size_t length, Eina_File_Map_Prot prot, Eina_File_Map_Flag flags, off_t offset)
942{
943 if (!file)
944 return NULL;
945
946 if (length > (size_t)file->file_size)
947 {
948 ERR("Wrong length");
949 return NULL;
950 }
951
952 file->map_size = length;
953
954 return mmap(start, file->map_size, prot, flags, file->fd, offset);
955}
956
957EAPI Eina_Bool
958eina_file_unmap(Eina_File *file, void *start)
959{
960 if (!file)
961 return EINA_FALSE;
962
963 return (munmap(start, file->map_size) == 0) ? EINA_TRUE : EINA_FALSE;
964}
965
966/** 688/**
967 * @} 689 * @}
968 */ 690 */