aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/3rdparty/smount/smount.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/3rdparty/smount/smount.c')
-rw-r--r--src/libjin/3rdparty/smount/smount.c31
1 files changed, 8 insertions, 23 deletions
diff --git a/src/libjin/3rdparty/smount/smount.c b/src/libjin/3rdparty/smount/smount.c
index 2b4e9b9..6214800 100644
--- a/src/libjin/3rdparty/smount/smount.c
+++ b/src/libjin/3rdparty/smount/smount.c
@@ -44,7 +44,7 @@ smtShared* smtnewshared()
/**
* Concatenate strings together.
*/
-char *concat(const char *str, ...) {
+char* concat(const char *str, ...) {
va_list args;
const char *s;
// Get len
@@ -66,7 +66,7 @@ char *concat(const char *str, ...) {
return res;
}
-static int isdir(const char *path) {
+static int isdir(const char* path) {
struct stat s;
int res = stat(path, &s);
return S_ISDIR(s.st_mode);
@@ -75,12 +75,8 @@ static int isdir(const char *path) {
int smtmount(smtShared* S, const char *path)
{
if (!isdir(path))
- {
return SMT_INVALIDMOUNT;
- }
-
S->mount = smtnewpath(PATH_DIR, path, 0);
-
return SMT_SUCCESS;
}
@@ -132,33 +128,22 @@ const char* smterrstr(int e)
{
switch (e)
{
- case SMT_INVALIDMOUNT: return "invalid mount directory";
- default: return "unknown error";
+ case SMT_INVALIDMOUNT: return "invalid mount directory";
+ default: return "unknown error";
}
}
void *smtread(smtShared* S, const char *path, unsigned int *size)
{
- if (!smtisreg(S, path)) return 0;
- int fr = 0;
- if (size == 0)
- {
- fr = 1;
- size = (unsigned int*)malloc(sizeof(unsigned int));
- }
+ if (size == NULL) return NULL;
+ if (!smtisreg(S, path)) return NULL;
char *r = concat(S->mount->path, "/", path, NULL);
if (!r)
- {
- free(size);
return NULL;
- }
FILE *fp = fopen(r, "rb");
free(r);
if (!fp)
- {
- free(size);
return 0;
- }
/* Get file size */
fseek(fp, 0, SEEK_END);
*size = ftell(fp);
@@ -167,13 +152,13 @@ void *smtread(smtShared* S, const char *path, unsigned int *size)
char *res = (char*)malloc(*size + 1);
if (!res) return NULL;
res[*size] = '\0';
- if (fread(res, 1, *size, fp) != *size) {
+ if (fread(res, 1, *size, fp) != *size)
+ {
free(res);
fclose(fp);
return NULL;
}
fclose(fp);
- if (fr) free(size);
return res;
}