Improve file API
Prefix symbols and constants names and improve documentation.
This commit is contained in:
@@ -6,8 +6,8 @@
|
||||
#include "util/log.h"
|
||||
|
||||
char *
|
||||
get_local_file_path(const char *name) {
|
||||
char *executable_path = get_executable_path();
|
||||
sc_file_get_local_path(const char *name) {
|
||||
char *executable_path = sc_file_get_executable_path();
|
||||
if (!executable_path) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -15,10 +15,10 @@ get_local_file_path(const char *name) {
|
||||
// dirname() does not work correctly everywhere, so get the parent
|
||||
// directory manually.
|
||||
// See <https://github.com/Genymobile/scrcpy/issues/2619>
|
||||
char *p = strrchr(executable_path, PATH_SEPARATOR);
|
||||
char *p = strrchr(executable_path, SC_PATH_SEPARATOR);
|
||||
if (!p) {
|
||||
LOGE("Unexpected executable path: \"%s\" (it should contain a '%c')",
|
||||
executable_path, PATH_SEPARATOR);
|
||||
executable_path, SC_PATH_SEPARATOR);
|
||||
free(executable_path);
|
||||
return NULL;
|
||||
}
|
||||
@@ -37,7 +37,7 @@ get_local_file_path(const char *name) {
|
||||
}
|
||||
|
||||
memcpy(file_path, dir, dirlen);
|
||||
file_path[dirlen] = PATH_SEPARATOR;
|
||||
file_path[dirlen] = SC_PATH_SEPARATOR;
|
||||
// namelen + 1 to copy the final '\0'
|
||||
memcpy(&file_path[dirlen + 1], name, namelen + 1);
|
||||
|
||||
|
||||
@@ -6,29 +6,44 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
# define PATH_SEPARATOR '\\'
|
||||
# define SC_PATH_SEPARATOR '\\'
|
||||
#else
|
||||
# define PATH_SEPARATOR '/'
|
||||
# define SC_PATH_SEPARATOR '/'
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
// only used to find package manager, not implemented for Windows
|
||||
/**
|
||||
* Indicate if an executable exists using $PATH
|
||||
*
|
||||
* In practice, it is only used to know if a package manager is available on
|
||||
* the system. It is only implemented on Linux.
|
||||
*/
|
||||
bool
|
||||
search_executable(const char *file);
|
||||
sc_file_executable_exists(const char *file);
|
||||
#endif
|
||||
|
||||
// return the absolute path of the executable (the scrcpy binary)
|
||||
// may be NULL on error; to be freed by free()
|
||||
/**
|
||||
* Return the absolute path of the executable (the scrcpy binary)
|
||||
*
|
||||
* The result must be freed by the caller using free(). It may return NULL on
|
||||
* error.
|
||||
*/
|
||||
char *
|
||||
get_executable_path(void);
|
||||
sc_file_get_executable_path(void);
|
||||
|
||||
// Return the absolute path of a file in the same directory as he executable.
|
||||
// May be NULL on error. To be freed by free().
|
||||
/**
|
||||
* Return the absolute path of a file in the same directory as the executable
|
||||
*
|
||||
* The result must be freed by the caller using free(). It may return NULL on
|
||||
* error.
|
||||
*/
|
||||
char *
|
||||
get_local_file_path(const char *name);
|
||||
sc_file_get_local_path(const char *name);
|
||||
|
||||
// returns true if the file exists and is not a directory
|
||||
/**
|
||||
* Indicate if the file exists and is not a directory
|
||||
*/
|
||||
bool
|
||||
is_regular_file(const char *path);
|
||||
sc_file_is_regular(const char *path);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user