ReactOS 0.4.16-dev-237-gd6eebaa
saveargs.c File Reference
#include <schily/mconfig.h>
#include <schily/standard.h>
#include <schily/string.h>
#include <schily/stdlib.h>
#include <schily/avoffset.h>
#include <schily/schily.h>
#include <schily/dlfcn.h>
Include dependency graph for saveargs.c:

Go to the source code of this file.

Functions

LOCAL void save_av0 __PR ((char *av0))
 
LOCAL void init_progname __PR ((void))
 
EXPORT void save_args (int ac, av)
 
LOCAL void save_av0 (char *av0)
 
EXPORT int saved_ac ()
 
EXPORT char ** saved_av ()
 
EXPORT charsaved_av0 ()
 
EXPORT void set_progname (char *name) const
 
EXPORT charget_progname ()
 
EXPORT charget_progpath ()
 
LOCAL void init_progname ()
 
LOCAL void init_arginfo ()
 

Variables

static int ac_saved
 
static char ** av_saved
 
static charav0_saved
 
static charav0_name_saved
 
static charprogpath_saved
 
static charprogname_saved
 
static char av0_sp [32]
 
static char prn_sp [32]
 
static char dfl_str [] = "?"
 

Function Documentation

◆ __PR() [1/2]

LOCAL void save_av0 __PR ( (char *av0)  )

◆ __PR() [2/2]

LOCAL void init_progname __PR ( (void )

◆ get_progname()

EXPORT char * get_progname ( )

Definition at line 151 of file saveargs.c.

152{
153 if (progname_saved)
154 return (progname_saved);
155 if (av0_name_saved == NULL)
157 if (av0_name_saved)
158 return (av0_name_saved);
159 return (dfl_str);
160}
#define NULL
Definition: types.h:112
static char dfl_str[]
Definition: saveargs.c:51
LOCAL void init_progname()
Definition: saveargs.c:175
static char * progname_saved
Definition: saveargs.c:47
static char * av0_name_saved
Definition: saveargs.c:45

Referenced by _comerr(), and searchfileinpath().

◆ get_progpath()

EXPORT char * get_progpath ( )

Definition at line 163 of file saveargs.c.

164{
165 if (progpath_saved)
166 return (progpath_saved);
167 if (av0_saved == NULL)
169 if (av0_saved)
170 return (av0_saved);
171 return (dfl_str);
172}
static char * progpath_saved
Definition: saveargs.c:46
static char * av0_saved
Definition: saveargs.c:44

◆ init_arginfo()

LOCAL void init_arginfo ( )

Definition at line 208 of file saveargs.c.

209{
210#if defined(HAVE_DLINFO) && defined(HAVE_DLOPEN_IN_LIBC) && defined(RTLD_DI_ARGSINFO)
211 Dl_argsinfo args;
212
213 if (dlinfo(RTLD_SELF, RTLD_DI_ARGSINFO, &args) < 0 ||
214 args.dla_argc <= 0 ||
215 args.dla_argv[0] == NULL)
216 return;
217
218 if (av_saved == NULL)
219 save_args(args.dla_argc, args.dla_argv);
220#endif
221}
EXPORT void save_args(int ac, av)
Definition: saveargs.c:58
static char ** av_saved
Definition: saveargs.c:43
#define args
Definition: format.c:66
Definition: match.c:390

Referenced by init_progname(), saved_ac(), saved_av(), and saved_av0().

◆ init_progname()

LOCAL void init_progname ( )

Definition at line 175 of file saveargs.c.

176{
177#if defined(HAVE_SCANSTACK) || defined(HAVE_GETPROGNAME)
178 char *progname;
179#endif
180
181 if (av0_name_saved == NULL)
182 init_arginfo();
183 if (av0_name_saved)
184 return;
185#ifdef HAVE_GETPROGNAME
186 progname = (char *)getprogname();
187 if (progname) {
189 return;
190 }
191#endif
192#ifdef HAVE_VAR___PROGNAME
193 if (__progname_full) {
194 save_av0(__progname_full);
195 return;
196 }
197#endif
198#ifdef HAVE_SCANSTACK
199 progname = getav0(); /* scan stack to get argv[0] */
200 if (progname) {
202 return;
203 }
204#endif
205}
static const char * progname
Definition: cjpeg.c:137
LOCAL void save_av0(char *av0)
Definition: saveargs.c:68
LOCAL void init_arginfo()
Definition: saveargs.c:208

Referenced by get_progname(), and get_progpath().

◆ save_args()

EXPORT void save_args ( int  ac,
av   
)

Definition at line 58 of file saveargs.c.

61{
62 ac_saved = ac;
63 av_saved = av;
64 save_av0(av[0]);
65}
static int ac_saved
Definition: saveargs.c:42

Referenced by init_arginfo(), and main().

◆ save_av0()

LOCAL void save_av0 ( char av0)

Definition at line 68 of file saveargs.c.

70{
71 int slen;
72 char *p;
73
74 if (av0_saved && av0_saved != av0_sp)
76
77 slen = strlen(av0) + 1;
78
79 if (slen <= (int)sizeof (av0_sp))
81 else
82 av0_saved = malloc(slen);
83
84 if (av0_saved) {
85 strcpy(av0_saved, av0);
86 av0 = av0_saved;
87 }
88
89 if ((p = strrchr(av0, '/')) == NULL)
90 av0_name_saved = av0;
91 else
92 av0_name_saved = ++p;
93}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
GLfloat GLfloat p
Definition: glext.h:8902
static char av0_sp[32]
Definition: saveargs.c:49
_CRT_RESTORE_GCC_WARNINGS _CRT_DISABLE_GCC_WARNINGS _Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)

Referenced by init_progname(), and save_args().

◆ saved_ac()

EXPORT int saved_ac ( )

Definition at line 96 of file saveargs.c.

97{
98 if (av_saved == NULL)
100
101 return (ac_saved);
102}

Referenced by vers_write().

◆ saved_av()

EXPORT char ** saved_av ( )

Definition at line 105 of file saveargs.c.

106{
107 if (av_saved == NULL)
108 init_arginfo();
109
110 return (av_saved);
111}

Referenced by vers_write().

◆ saved_av0()

EXPORT char * saved_av0 ( )

Definition at line 114 of file saveargs.c.

115{
116 if (av0_saved == NULL)
117 init_arginfo();
118
119 return (av0_saved);
120}

◆ set_progname()

EXPORT void set_progname ( char name) const

Definition at line 123 of file saveargs.c.

125{
126 int slen;
127 char *p;
128
131
132 slen = strlen(name) + 1;
133
134 if (slen <= sizeof (prn_sp))
136 else
137 progpath_saved = malloc(slen);
138
139 if (progpath_saved) {
142 }
143
144 if ((p = strrchr(name, '/')) == NULL)
145 progname_saved = (char *)name;
146 else
147 progname_saved = ++p;
148}
static char prn_sp[32]
Definition: saveargs.c:50
Definition: name.c:39

Variable Documentation

◆ ac_saved

int ac_saved
static

Definition at line 42 of file saveargs.c.

Referenced by save_args(), and saved_ac().

◆ av0_name_saved

char* av0_name_saved
static

Definition at line 45 of file saveargs.c.

Referenced by get_progname(), init_progname(), and save_av0().

◆ av0_saved

char* av0_saved
static

Definition at line 44 of file saveargs.c.

Referenced by get_progpath(), save_av0(), and saved_av0().

◆ av0_sp

char av0_sp[32]
static

Definition at line 49 of file saveargs.c.

Referenced by save_av0().

◆ av_saved

char** av_saved
static

Definition at line 43 of file saveargs.c.

Referenced by init_arginfo(), save_args(), saved_ac(), and saved_av().

◆ dfl_str

char dfl_str[] = "?"
static

Definition at line 51 of file saveargs.c.

Referenced by get_progname(), and get_progpath().

◆ prn_sp

char prn_sp[32]
static

Definition at line 50 of file saveargs.c.

Referenced by set_progname().

◆ progname_saved

char* progname_saved
static

Definition at line 47 of file saveargs.c.

Referenced by get_progname(), and set_progname().

◆ progpath_saved

char* progpath_saved
static

Definition at line 46 of file saveargs.c.

Referenced by get_progpath(), and set_progname().