mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Add subsurface_access()
For our usage the method will acept UTF-8 paths, which are converted to UTF-16 on Win32. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
61dc19d2e0
commit
4096383fb5
5 changed files with 26 additions and 2 deletions
1
dive.h
1
dive.h
|
@ -653,6 +653,7 @@ extern int subsurface_rename(const char *path, const char *newpath);
|
||||||
extern int subsurface_open(const char *path, int oflags, mode_t mode);
|
extern int subsurface_open(const char *path, int oflags, mode_t mode);
|
||||||
extern FILE *subsurface_fopen(const char *path, const char *mode);
|
extern FILE *subsurface_fopen(const char *path, const char *mode);
|
||||||
extern void *subsurface_opendir(const char *path);
|
extern void *subsurface_opendir(const char *path);
|
||||||
|
extern int subsurface_access(const char *path, int mode);
|
||||||
extern struct zip *subsurface_zip_open_readonly(const char *path, int flags, int *errorp);
|
extern struct zip *subsurface_zip_open_readonly(const char *path, int flags, int *errorp);
|
||||||
extern int subsurface_zip_close(struct zip *zip);
|
extern int subsurface_zip_close(struct zip *zip);
|
||||||
extern void subsurface_console_init(bool dedicated);
|
extern void subsurface_console_init(bool dedicated);
|
||||||
|
|
|
@ -849,7 +849,7 @@ const char *do_libdivecomputer_import(device_data_t *data)
|
||||||
err = do_device_import(data);
|
err = do_device_import(data);
|
||||||
/* TODO: Show the logfile to the user on error. */
|
/* TODO: Show the logfile to the user on error. */
|
||||||
dc_device_close(data->device);
|
dc_device_close(data->device);
|
||||||
} else if (access(data->devname, R_OK | W_OK) != 0)
|
} else if (subsurface_access(data->devname, R_OK | W_OK) != 0)
|
||||||
err = translate("gettextFromC", "Insufficient privileges to open the device %s %s (%s)");
|
err = translate("gettextFromC", "Insufficient privileges to open the device %s %s (%s)");
|
||||||
|
|
||||||
dc_context_free(data->context);
|
dc_context_free(data->context);
|
||||||
|
|
5
linux.c
5
linux.c
|
@ -164,6 +164,11 @@ void *subsurface_opendir(const char *path)
|
||||||
return (void *)opendir(path);
|
return (void *)opendir(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int subsurface_access(const char *path, int mode)
|
||||||
|
{
|
||||||
|
return access(path, mode);
|
||||||
|
}
|
||||||
|
|
||||||
struct zip *subsurface_zip_open_readonly(const char *path, int flags, int *errorp)
|
struct zip *subsurface_zip_open_readonly(const char *path, int flags, int *errorp)
|
||||||
{
|
{
|
||||||
return zip_open(path, flags, errorp);
|
return zip_open(path, flags, errorp);
|
||||||
|
|
7
macos.c
7
macos.c
|
@ -11,7 +11,7 @@
|
||||||
#include <sys/syslimits.h>
|
#include <sys/syslimits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <dirent.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
void subsurface_user_info(struct user_info *info)
|
void subsurface_user_info(struct user_info *info)
|
||||||
{ /* Nothing, let's use libgit2-20 on MacOS */ }
|
{ /* Nothing, let's use libgit2-20 on MacOS */ }
|
||||||
|
@ -147,6 +147,11 @@ void *subsurface_opendir(const char *path)
|
||||||
return (void *)opendir(path);
|
return (void *)opendir(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int subsurface_access(const char *path, int mode)
|
||||||
|
{
|
||||||
|
return access(path, mode);
|
||||||
|
}
|
||||||
|
|
||||||
struct zip *subsurface_zip_open_readonly(const char *path, int flags, int *errorp)
|
struct zip *subsurface_zip_open_readonly(const char *path, int flags, int *errorp)
|
||||||
{
|
{
|
||||||
return zip_open(path, flags, errorp);
|
return zip_open(path, flags, errorp);
|
||||||
|
|
13
windows.c
13
windows.c
|
@ -1,5 +1,6 @@
|
||||||
/* windows.c */
|
/* windows.c */
|
||||||
/* implements Windows specific functions */
|
/* implements Windows specific functions */
|
||||||
|
#include <io.h>
|
||||||
#include "dive.h"
|
#include "dive.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#undef _WIN32_WINNT
|
#undef _WIN32_WINNT
|
||||||
|
@ -235,6 +236,18 @@ void *subsurface_opendir(const char *path)
|
||||||
return (void *)ret;
|
return (void *)ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int subsurface_access(const char *path, int mode)
|
||||||
|
{
|
||||||
|
int ret = -1;
|
||||||
|
if (!path)
|
||||||
|
return ret;
|
||||||
|
wchar_t *wpath = utf8_to_utf16(path);
|
||||||
|
if (wpath)
|
||||||
|
ret = _waccess(wpath, mode);
|
||||||
|
free((void *)wpath);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef O_BINARY
|
#ifndef O_BINARY
|
||||||
#define O_BINARY 0
|
#define O_BINARY 0
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue