mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-18 02:39:44 +00:00
Move get_self_executable_path() into "os.h"/os.c
This commit is contained in:
parent
df1814309b
commit
f606daebc6
14
log.c
14
log.c
@ -722,20 +722,6 @@ void logConfigChanged()
|
||||
logFlush();
|
||||
}
|
||||
|
||||
ssize_t get_self_executable_path(char *buf, size_t len)
|
||||
{
|
||||
#if defined(linux)
|
||||
return read_symlink("/proc/self/exe", buf, len);
|
||||
#elif defined (__sun__)
|
||||
return read_symlink("/proc/self/path/a.out", buf, len);
|
||||
#elif defined (__APPLE__)
|
||||
uint32_t bufsize = len;
|
||||
return _NSGetExecutablePath(buf, &bufsize) == -1 && len ? -1 : bufsize;
|
||||
#else
|
||||
#error Unable to find executable path
|
||||
#endif
|
||||
}
|
||||
|
||||
int log_backtrace(int level, struct __sourceloc whence)
|
||||
{
|
||||
#ifndef NO_BACKTRACE
|
||||
|
1
log.h
1
log.h
@ -104,7 +104,6 @@ __attribute__ (( format(printf,3,4) ));
|
||||
void vlogMessage(int level, struct __sourceloc whence, const char *fmt, va_list);
|
||||
void logConfigChanged();
|
||||
int logDump(int level, struct __sourceloc whence, char *name, const unsigned char *addr, size_t len);
|
||||
ssize_t get_self_executable_path(char *buf, size_t len);
|
||||
int log_backtrace(int level, struct __sourceloc whence);
|
||||
|
||||
struct strbuf;
|
||||
|
14
os.c
14
os.c
@ -332,3 +332,17 @@ int alter_file_meta(const char *path, const struct file_meta *origp, struct file
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
ssize_t get_self_executable_path(char *buf, size_t len)
|
||||
{
|
||||
#if defined(linux)
|
||||
return read_symlink("/proc/self/exe", buf, len);
|
||||
#elif defined (__sun__)
|
||||
return read_symlink("/proc/self/path/a.out", buf, len);
|
||||
#elif defined (__APPLE__)
|
||||
uint32_t bufsize = len;
|
||||
return _NSGetExecutablePath(buf, &bufsize) == -1 && len ? -1 : bufsize;
|
||||
#else
|
||||
#error Unable to find executable path
|
||||
#endif
|
||||
}
|
||||
|
11
os.h
11
os.h
@ -203,4 +203,15 @@ int cmp_file_meta(const struct file_meta *a, const struct file_meta *b);
|
||||
// by bumping the file's modification time or altering its inode.
|
||||
int alter_file_meta(const char *path, const struct file_meta *origp, struct file_meta *metap);
|
||||
|
||||
/* Fill the given buffer with the nul-terminated absolute path of the calling
|
||||
* process's executable. Logs an error and returns -1 if the executable cannot
|
||||
* be determined or the supplied buffer is too short. Otherwise returns the
|
||||
* number of bytes placed in the buffer, including the terminating nul (ie,
|
||||
* returns strlen(buf) + 1).
|
||||
*
|
||||
* @author Andrew Bettison <andrew@servalproject.com>
|
||||
*/
|
||||
ssize_t get_self_executable_path(char *buf, size_t len);
|
||||
|
||||
#endif //__SERVAL_DNA__OS_H
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user