From: Jean-Philippe Orsini Date: Wed, 14 Dec 2011 01:07:22 +0000 (+0000) Subject: removed some useless code X-Git-Tag: v0.8.0.5~504 X-Git-Url: https://git.wpitchoune.net/gitweb/?p=psensor.git;a=commitdiff_plain;h=a3c71b73815825dcd686f30a3b0012c169dab6d6 removed some useless code mv src/lib/p_io.* to src/lib/pio.* --- diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 7082480..9fa01e7 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -12,7 +12,7 @@ libpsensor_a_SOURCES = \ hdd.h\ nvidia.h \ lmsensor.h lmsensor.c \ - p_io.h p_io.c \ + pio.h pio.c \ url.c url.h AM_CPPFLAGS= diff --git a/src/lib/Makefile.in b/src/lib/Makefile.in index eb4a824..5ddcf1e 100644 --- a/src/lib/Makefile.in +++ b/src/lib/Makefile.in @@ -66,7 +66,7 @@ libpsensor_a_AR = $(AR) $(ARFLAGS) libpsensor_a_LIBADD = am__libpsensor_a_SOURCES_DIST = amd.h cpu.h measure.h measure.c \ color.h color.c log.h log.c psensor.h psensor.c hdd.h nvidia.h \ - lmsensor.h lmsensor.c p_io.h p_io.c url.c url.h hdd_atasmart.c \ + lmsensor.h lmsensor.c pio.h pio.c url.c url.h hdd_atasmart.c \ hdd_hddtemp.c nvidia.c amd.c cpu.c psensor_json.h \ psensor_json.c @ATASMART_TRUE@am__objects_1 = libpsensor_a-hdd_atasmart.$(OBJEXT) @@ -78,7 +78,7 @@ am__libpsensor_a_SOURCES_DIST = amd.h cpu.h measure.h measure.c \ am_libpsensor_a_OBJECTS = libpsensor_a-measure.$(OBJEXT) \ libpsensor_a-color.$(OBJEXT) libpsensor_a-log.$(OBJEXT) \ libpsensor_a-psensor.$(OBJEXT) libpsensor_a-lmsensor.$(OBJEXT) \ - libpsensor_a-p_io.$(OBJEXT) libpsensor_a-url.$(OBJEXT) \ + libpsensor_a-pio.$(OBJEXT) libpsensor_a-url.$(OBJEXT) \ $(am__objects_1) $(am__objects_2) $(am__objects_3) \ $(am__objects_4) $(am__objects_5) $(am__objects_6) libpsensor_a_OBJECTS = $(am_libpsensor_a_OBJECTS) @@ -246,7 +246,7 @@ noinst_LIBRARIES = libpsensor.a libpsensor_a_CFLAGS = -Wall -Werror $(am__append_9) libpsensor_a_SOURCES = amd.h cpu.h measure.h measure.c color.h color.c \ log.h log.c psensor.h psensor.c hdd.h nvidia.h lmsensor.h \ - lmsensor.c p_io.h p_io.c url.c url.h $(am__append_1) \ + lmsensor.c pio.h pio.c url.c url.h $(am__append_1) \ $(am__append_4) $(am__append_5) $(am__append_8) \ $(am__append_10) $(am__append_13) AM_CPPFLAGS = $(am__append_3) $(am__append_7) $(am__append_12) \ @@ -313,7 +313,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpsensor_a-log.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpsensor_a-measure.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpsensor_a-nvidia.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpsensor_a-p_io.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpsensor_a-pio.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpsensor_a-psensor.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpsensor_a-psensor_json.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libpsensor_a-url.Po@am__quote@ @@ -402,19 +402,19 @@ libpsensor_a-lmsensor.obj: lmsensor.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpsensor_a_CFLAGS) $(CFLAGS) -c -o libpsensor_a-lmsensor.obj `if test -f 'lmsensor.c'; then $(CYGPATH_W) 'lmsensor.c'; else $(CYGPATH_W) '$(srcdir)/lmsensor.c'; fi` -libpsensor_a-p_io.o: p_io.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpsensor_a_CFLAGS) $(CFLAGS) -MT libpsensor_a-p_io.o -MD -MP -MF $(DEPDIR)/libpsensor_a-p_io.Tpo -c -o libpsensor_a-p_io.o `test -f 'p_io.c' || echo '$(srcdir)/'`p_io.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpsensor_a-p_io.Tpo $(DEPDIR)/libpsensor_a-p_io.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='p_io.c' object='libpsensor_a-p_io.o' libtool=no @AMDEPBACKSLASH@ +libpsensor_a-pio.o: pio.c +@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpsensor_a_CFLAGS) $(CFLAGS) -MT libpsensor_a-pio.o -MD -MP -MF $(DEPDIR)/libpsensor_a-pio.Tpo -c -o libpsensor_a-pio.o `test -f 'pio.c' || echo '$(srcdir)/'`pio.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpsensor_a-pio.Tpo $(DEPDIR)/libpsensor_a-pio.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pio.c' object='libpsensor_a-pio.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpsensor_a_CFLAGS) $(CFLAGS) -c -o libpsensor_a-p_io.o `test -f 'p_io.c' || echo '$(srcdir)/'`p_io.c +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpsensor_a_CFLAGS) $(CFLAGS) -c -o libpsensor_a-pio.o `test -f 'pio.c' || echo '$(srcdir)/'`pio.c -libpsensor_a-p_io.obj: p_io.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpsensor_a_CFLAGS) $(CFLAGS) -MT libpsensor_a-p_io.obj -MD -MP -MF $(DEPDIR)/libpsensor_a-p_io.Tpo -c -o libpsensor_a-p_io.obj `if test -f 'p_io.c'; then $(CYGPATH_W) 'p_io.c'; else $(CYGPATH_W) '$(srcdir)/p_io.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpsensor_a-p_io.Tpo $(DEPDIR)/libpsensor_a-p_io.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='p_io.c' object='libpsensor_a-p_io.obj' libtool=no @AMDEPBACKSLASH@ +libpsensor_a-pio.obj: pio.c +@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpsensor_a_CFLAGS) $(CFLAGS) -MT libpsensor_a-pio.obj -MD -MP -MF $(DEPDIR)/libpsensor_a-pio.Tpo -c -o libpsensor_a-pio.obj `if test -f 'pio.c'; then $(CYGPATH_W) 'pio.c'; else $(CYGPATH_W) '$(srcdir)/pio.c'; fi` +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libpsensor_a-pio.Tpo $(DEPDIR)/libpsensor_a-pio.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='pio.c' object='libpsensor_a-pio.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpsensor_a_CFLAGS) $(CFLAGS) -c -o libpsensor_a-p_io.obj `if test -f 'p_io.c'; then $(CYGPATH_W) 'p_io.c'; else $(CYGPATH_W) '$(srcdir)/p_io.c'; fi` +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpsensor_a_CFLAGS) $(CFLAGS) -c -o libpsensor_a-pio.obj `if test -f 'pio.c'; then $(CYGPATH_W) 'pio.c'; else $(CYGPATH_W) '$(srcdir)/pio.c'; fi` libpsensor_a-url.o: url.c @am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libpsensor_a_CFLAGS) $(CFLAGS) -MT libpsensor_a-url.o -MD -MP -MF $(DEPDIR)/libpsensor_a-url.Tpo -c -o libpsensor_a-url.o `test -f 'url.c' || echo '$(srcdir)/'`url.c diff --git a/src/lib/p_io.c b/src/lib/p_io.c deleted file mode 100644 index 279b3f0..0000000 --- a/src/lib/p_io.c +++ /dev/null @@ -1,296 +0,0 @@ -/* - * Copyright (C) 2010-2011 jeanfi@gmail.com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ -#include -#include -#include -#include -#include - -#include "p_io.h" - -int is_dir(const char *path) -{ - struct stat st; - - int ret = lstat(path, &st); - - if (ret == 0 && S_ISDIR(st.st_mode)) - return 1; - - return 0; -} - -int is_file(const char *path) -{ - struct stat st; - - int ret = lstat(path, &st); - - if (ret == 0 && S_ISREG(st.st_mode)) - return 1; - - return 0; -} - -char *dir_normalize(const char *dpath) -{ - char *npath; - int n; - - if (!dpath || !strlen(dpath)) - return NULL; - - npath = strdup(dpath); - - n = strlen(npath); - - if (n > 1 && npath[n - 1] == '/') - npath[n - 1] = '\0'; - - return npath; -} - -char **dir_list(const char *dpath, int (*filter) (const char *path)) -{ - struct dirent *ent; - DIR *dir; - char **paths; - int n; - - dir = opendir(dpath); - - if (!dir) - return NULL; - - n = 1; - paths = malloc(sizeof(void *)); - *paths = NULL; - - while ((ent = readdir(dir)) != NULL) { - char *fpath; - char *name = ent->d_name; - - if (!strcmp(name, ".") || !strcmp(name, "..")) - continue; - - fpath = malloc(strlen(dpath) + 1 + strlen(name) + 1); - - strcpy(fpath, dpath); - strcat(fpath, "/"); - strcat(fpath, name); - - if (!filter || filter(fpath)) { - char **npaths; - - n++; - npaths = malloc(n * sizeof(void *)); - memcpy(npaths + 1, paths, (n - 1) * sizeof(void *)); - free(paths); - paths = npaths; - *npaths = fpath; - - } else { - free(fpath); - } - } - - closedir(dir); - - return paths; -} - -void paths_free(char **paths) -{ - char **paths_cur; - - paths_cur = paths; - while (*paths_cur) { - free(*paths_cur); - - paths_cur++; - } - - free(paths); -} - -char *file_get_content(const char *fpath) -{ - long size; - - char *page; - - size = file_get_size(fpath); - - if (size == -1) { - page = NULL; - - } else if (size == 0) { - page = malloc(1); - *page = '\0'; - - } else { - FILE *fp = fopen(fpath, "rb"); - if (fp) { - page = malloc(size + 1); - if (!page || size != fread(page, 1, size, fp)) { - free(page); - return NULL; - } - - *(page + size) = '\0'; - - fclose(fp); - } else { - page = NULL; - } - } - - return page; -} - -long file_get_size(const char *path) -{ - FILE *fp; - - if (!is_file(path)) - return -1; - - fp = fopen(path, "rb"); - if (fp) { - long size; - - if (fseek(fp, 0, SEEK_END) == -1) - return -1; - - size = ftell(fp); - - fclose(fp); - - return size; - } - - return -1; -} - -#define FCOPY_BUF_SZ 4096 -static int FILE_copy(FILE *src, FILE *dst) -{ - int ret = 0; - char *buf = malloc(FCOPY_BUF_SZ); - int n; - - if (!buf) - return FILE_COPY_ERROR_ALLOC_BUFFER; - - while (!ret) { - n = fread(buf, 1, FCOPY_BUF_SZ, src); - if (n) { - if (fwrite(buf, 1, n, dst) != n) - ret = FILE_COPY_ERROR_WRITE; - } else { - if (!feof(src)) - ret = FILE_COPY_ERROR_READ; - else - break; - } - } - - free(buf); - - return ret; -} - -int -file_copy(const char *src, const char *dst) -{ - FILE *fsrc, *fdst; - int ret = 0; - - fsrc = fopen(src, "r"); - - if (fsrc) { - fdst = fopen(dst, "w+"); - - if (fdst) { - ret = FILE_copy(fsrc, fdst); - fclose(fdst); - } else { - ret = FILE_COPY_ERROR_OPEN_DST; - } - - fclose(fsrc); - } else { - ret = FILE_COPY_ERROR_OPEN_SRC; - } - - return ret; -} - -char *path_append(const char *dir, const char *path) -{ - char *ret, *ndir; - - ndir = dir_normalize(dir); - - if (!ndir && (!path || !strlen(path))) - ret = NULL; - - else if (!ndir) { - ret = strdup(path); - - } else if (!path || !strlen(path)) { - return ndir; - - } else { - ret = malloc(strlen(ndir) + 1 + strlen(path) + 1); - strcpy(ret, ndir); - strcat(ret, "/"); - strcat(ret, path); - } - - free(ndir); - - return ret; -} - -void -file_copy_print_error(int code, const char *src, const char *dst) -{ - switch (code) { - case 0: - break; - case FILE_COPY_ERROR_OPEN_SRC: - printf("File copy error: failed to open %s.\n", src); - break; - case FILE_COPY_ERROR_OPEN_DST: - printf("File copy error: failed to open %s.\n", dst); - break; - case FILE_COPY_ERROR_READ: - printf("File copy error: failed to read %s.\n", src); - break; - case FILE_COPY_ERROR_WRITE: - printf("File copy error: failed to write %s.\n", src); - break; - case FILE_COPY_ERROR_ALLOC_BUFFER: - printf("File copy error: failed to allocate buffer.\n"); - break; - default: - printf("File copy error: unknown error %d.\n", code); - } -} diff --git a/src/lib/p_io.h b/src/lib/p_io.h deleted file mode 100644 index b26b7c5..0000000 --- a/src/lib/p_io.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2010-2011 jeanfi@gmail.com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301 USA - */ -#ifndef _P_IO_H -#define _P_IO_H - -/* Returns '1' if a given 'path' denotates a directory else returns - 0 */ -int is_dir(const char *path); - -/* Returns '1' if a given 'path' denotates a file else returns - 0 */ -int is_file(const char *path); - -/* Returns a normalized path */ -char *path_normalize(const char *dpath); - -/* Returns the null-terminated entries of a directory */ -char **dir_list(const char *dpath, int (*filter) (const char *path)); -void paths_free(char **paths); - -char *path_append(const char *dir, const char *path); - -/* - Returns the size of a file. - Returns '-1' if the size cannot be retrieved or not a file. -*/ -long file_get_size(const char *path); - -/* - Returns the content of a file. - Returns 'NULL' if the file cannot be read or failed to allocate - enough memory. - Returns an empty string if the file exists but is empty. -*/ -char *file_get_content(const char *path); - -enum file_copy_error { - FILE_COPY_ERROR_OPEN_SRC = 1, - FILE_COPY_ERROR_OPEN_DST, - FILE_COPY_ERROR_READ, - FILE_COPY_ERROR_WRITE, - FILE_COPY_ERROR_ALLOC_BUFFER -}; - -void file_copy_print_error(int code, const char *src, const char *dst); - -/* - Copy a file. - - Returns '0' if sucessfull, otherwise return the error code. -*/ -int file_copy(const char *src, const char *dst); - -#endif diff --git a/src/lib/pio.c b/src/lib/pio.c new file mode 100644 index 0000000..54d9efb --- /dev/null +++ b/src/lib/pio.c @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2010-2011 jeanfi@gmail.com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#include +#include +#include +#include +#include + +#include "pio.h" + +char **dir_list(const char *dpath, int (*filter) (const char *path)) +{ + struct dirent *ent; + DIR *dir; + char **paths; + int n; + + dir = opendir(dpath); + + if (!dir) + return NULL; + + n = 1; + paths = malloc(sizeof(void *)); + *paths = NULL; + + while ((ent = readdir(dir)) != NULL) { + char *fpath; + char *name = ent->d_name; + + if (!strcmp(name, ".") || !strcmp(name, "..")) + continue; + + fpath = malloc(strlen(dpath) + 1 + strlen(name) + 1); + + strcpy(fpath, dpath); + strcat(fpath, "/"); + strcat(fpath, name); + + if (!filter || filter(fpath)) { + char **npaths; + + n++; + npaths = malloc(n * sizeof(void *)); + memcpy(npaths + 1, paths, (n - 1) * sizeof(void *)); + free(paths); + paths = npaths; + *npaths = fpath; + + } else { + free(fpath); + } + } + + closedir(dir); + + return paths; +} + +void paths_free(char **paths) +{ + char **paths_cur; + + paths_cur = paths; + while (*paths_cur) { + free(*paths_cur); + + paths_cur++; + } + + free(paths); +} + diff --git a/src/lib/pio.h b/src/lib/pio.h new file mode 100644 index 0000000..ab8cf63 --- /dev/null +++ b/src/lib/pio.h @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2010-2011 jeanfi@gmail.com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301 USA + */ +#ifndef _P_IO_H +#define _P_IO_H + +char **dir_list(const char *dpath, int (*filter) (const char *path)); +void paths_free(char **paths); + +#endif