projects
/
psensor.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fixed restoration of the panel divider position.
[psensor.git]
/
src
/
lib
/
pio.c
diff --git
a/src/lib/pio.c
b/src/lib/pio.c
index
4a1a6ce
..
1942348
100644
(file)
--- a/
src/lib/pio.c
+++ b/
src/lib/pio.c
@@
-1,5
+1,5
@@
/*
/*
- * Copyright (C) 2010-201
4
jeanfi@gmail.com
+ * Copyright (C) 2010-201
7
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
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@
-24,13
+24,13
@@
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
-#include <sys/types.h>
#include <plog.h>
#include <pio.h>
/* Directory separator is \ when cross-compiling for MS Windows
#include <plog.h>
#include <pio.h>
/* Directory separator is \ when cross-compiling for MS Windows
- systems */
+ * systems
+ */
#if defined(__MINGW32__)
#define DIRSEP ('\\')
#else
#if defined(__MINGW32__)
#define DIRSEP ('\\')
#else
@@
-63,7
+63,7
@@
int is_file(const char *path)
return 0;
}
return 0;
}
-char *dir_normalize(const char *dpath)
+
static
char *dir_normalize(const char *dpath)
{
char *npath;
int n;
{
char *npath;
int n;
@@
-150,11
+150,13
@@
void paths_free(char **paths)
char *file_get_content(const char *fpath)
{
char *file_get_content(const char *fpath)
{
- long size;
-
+ long size, n;
char *page;
char *page;
+ log_fct_enter();
+
size = file_get_size(fpath);
size = file_get_size(fpath);
+
if (size == -1) {
page = NULL;
if (size == -1) {
page = NULL;
@@
-164,46
+166,54
@@
char *file_get_content(const char *fpath)
} else {
FILE *fp = fopen(fpath, "rb");
} else {
FILE *fp = fopen(fpath, "rb");
+
if (fp) {
page = malloc(size + 1);
if (fp) {
page = malloc(size + 1);
- if (!page || size != fread(page, 1, size, fp)) {
- free(page);
- return NULL;
- }
- *(page + size) = '\0';
+ if (page) {
+ clearerr(fp);
+ n = fread(page, 1, size, fp);
+ if (n != size && ferror(fp)) {
+ free(page);
+ page = NULL;
+ } else {
+ *(page + n) = '\0';
+ }
+ }
fclose(fp);
} else {
fclose(fp);
} else {
+ log_debug("failed to open %s", fpath);
page = NULL;
}
}
page = NULL;
}
}
+ log_fct_exit();
+
return page;
}
long file_get_size(const char *path)
{
FILE *fp;
return page;
}
long file_get_size(const char *path)
{
FILE *fp;
+ long size;
if (!is_file(path))
return -1;
fp = fopen(path, "rb");
if (fp) {
if (!is_file(path))
return -1;
fp = fopen(path, "rb");
if (fp) {
- long size;
-
if (fseek(fp, 0, SEEK_END) == -1)
if (fseek(fp, 0, SEEK_END) == -1)
-
return
-1;
-
- size = ftell(fp);
+
size =
-1;
+ else
+
size = ftell(fp);
fclose(fp);
fclose(fp);
-
-
return size
;
+ } else {
+
size = -1
;
}
}
- return
-1
;
+ return
size
;
}
#define FCOPY_BUF_SZ 4096
}
#define FCOPY_BUF_SZ 4096