10#ifndef CLIBS_FILENAMES_H
11#define CLIBS_FILENAMES_H
19#define __FILE_NAME__ \
20 ( strrchr( __FILE__, '/' ) ? strrchr( __FILE__, '/' ) + 1 : __FILE__ )
25#if defined( __APPLE__ )
26#include <sys/syslimits.h>
27#elif defined( __linux__ )
28#include <linux/limits.h>
61 const char *last_slash = strrchr( full_path,
'/' );
62 if ( last_slash == NULL )
65 if ( *( last_slash + 1 ) !=
'\0' )
66 return last_slash + 1;
69 for (
const char *ptr = last_slash - 1; ptr >= full_path; --ptr )
94#if defined( __APPLE__ )
96#include <mach-o/dyld.h>
102 uint32_t size =
sizeof path;
103 if ( _NSGetExecutablePath( path, &size ) != 0 )
105 char *
const alloced = malloc( size );
106 if ( alloced == NULL || _NSGetExecutablePath( path, &size ) != 0 )
108 warn(
"not able to initialize prog name" );
121#elif defined( __linux__ )
128 if ( readlink(
"/proc/self/exe", path,
PATH_MAX ) == -1 )
Function and variable attributes.
#define LibraryDefined
Definition attributes.h:107
#define BeforeMain
Function runs before entering main
Definition attributes.h:75
LibraryDefined char ProgName[PATH_MAX+1]
Definition filenames.h:40
LibraryDefined const char * get_prog_name(void)
Definition filenames.h:81
BeforeMain LibraryDefined bool set_prog_name(void)
LibraryDefined const char * get_file_name(const char *const full_path)
Definition filenames.h:59
#define PATH_MAX
Maximum length of a file name.
Definition filenames.h:31