Isolate non-standard eaccess usage in a util function.

That will be replaced soon with our own implementation, based on POSIX 
standard functions.
release-1.5.4.branch
Vreixo Formoso 15 years ago
parent c786fc70b6
commit 702bd0f288
  1. 31
      src/fs_local.c
  2. 44
      src/util.c
  3. 10
      src/util.h

@ -13,9 +13,6 @@
#include "fsource.h"
#include "error.h"
/* for eaccess, define in unistd.h */
#define __USE_GNU
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
@ -154,33 +151,7 @@ int lfs_access(IsoFileSource *src)
}
data = src->data;
if (eaccess(data->path, R_OK) != 0) {
int err;
/* error, choose an appropriate return code */
switch (errno) {
case EACCES:
err = ISO_FILE_ACCESS_DENIED;
break;
case ENOTDIR:
case ENAMETOOLONG:
case ELOOP:
err = ISO_FILE_BAD_PATH;
break;
case ENOENT:
err = ISO_FILE_DOESNT_EXIST;
break;
case EFAULT:
case ENOMEM:
err = ISO_MEM_ERROR;
break;
default:
err = ISO_FILE_ERROR;
break;
}
return err;
}
return ISO_SUCCESS;
return iso_eaccess(data->path);
}
static

@ -19,6 +19,10 @@
#include <stdio.h>
#include <limits.h>
/* for eaccess, define in unistd.h */
#define __USE_GNU
#include <unistd.h>
int int_pow(int base, int power)
{
int result = 1;
@ -572,3 +576,43 @@ time_t iso_datetime_read_17(const uint8_t *buf)
return timegm(&tm) - buf[16] * 60 * 15;
}
/**
* Check whether the caller process has read access to the given local file.
*
* @return
* 1 on success (i.e, the process has read access), < 0 on error
* (including ISO_FILE_ACCESS_DENIED on access denied to the specified file
* or any directory on the path).
*/
int iso_eaccess(const char *path)
{
// TODO replace non-standard eaccess with our own implementation
if (eaccess(path, R_OK) != 0) {
int err;
/* error, choose an appropriate return code */
switch (errno) {
case EACCES:
err = ISO_FILE_ACCESS_DENIED;
break;
case ENOTDIR:
case ENAMETOOLONG:
case ELOOP:
err = ISO_FILE_BAD_PATH;
break;
case ENOENT:
err = ISO_FILE_DOESNT_EXIST;
break;
case EFAULT:
case ENOMEM:
err = ISO_MEM_ERROR;
break;
default:
err = ISO_FILE_ERROR;
break;
}
return err;
}
return ISO_SUCCESS;
}

@ -122,6 +122,16 @@ void iso_datetime_17(uint8_t *buf, time_t t);
time_t iso_datetime_read_7(const uint8_t *buf);
time_t iso_datetime_read_17(const uint8_t *buf);
/**
* Check whether the caller process has read access to the given local file.
*
* @return
* 1 on success (i.e, the process has read access), < 0 on error
* (including ISO_FILE_ACCESS_DENIED on access denied to the specified file
* or any directory on the path).
*/
int iso_eaccess(const char *path);
typedef struct iso_rbtree IsoRBTree;
/**

Loading…
Cancel
Save