ReactOS  0.4.11-dev-765-g5e024bf
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

LOCAL void save_av0 __PR ( (char *av0)  )
LOCAL void init_progname __PR ( (void )
EXPORT char* get_progname ( )

Definition at line 151 of file saveargs.c.

Referenced by _comerr(), and searchfileinpath().

152 {
153  if (progname_saved)
154  return (progname_saved);
155  if (av0_name_saved == NULL)
156  init_progname();
157  if (av0_name_saved)
158  return (av0_name_saved);
159  return (dfl_str);
160 }
smooth NULL
Definition: ftsmooth.c:416
static char * progname_saved
Definition: saveargs.c:47
LOCAL void init_progname()
Definition: saveargs.c:175
static char dfl_str[]
Definition: saveargs.c:51
static char * av0_name_saved
Definition: saveargs.c:45
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)
168  init_progname();
169  if (av0_saved)
170  return (av0_saved);
171  return (dfl_str);
172 }
smooth NULL
Definition: ftsmooth.c:416
static char * av0_saved
Definition: saveargs.c:44
LOCAL void init_progname()
Definition: saveargs.c:175
static char dfl_str[]
Definition: saveargs.c:51
static char * progpath_saved
Definition: saveargs.c:46
LOCAL void init_arginfo ( )

Definition at line 208 of file saveargs.c.

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

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 }
static char ** av_saved
Definition: saveargs.c:43
smooth NULL
Definition: ftsmooth.c:416
EXPORT void save_args(int ac, av)
Definition: saveargs.c:58
#define args
Definition: format.c:66
LOCAL void init_progname ( )

Definition at line 175 of file saveargs.c.

Referenced by get_progname(), and get_progpath().

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) {
188  save_av0(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) {
201  save_av0(progname);
202  return;
203  }
204 #endif
205 }
static const char * progname
Definition: cjpeg.c:137
smooth NULL
Definition: ftsmooth.c:416
static char * av0_name_saved
Definition: saveargs.c:45
LOCAL void save_av0(char *av0)
Definition: saveargs.c:68
LOCAL void init_arginfo()
Definition: saveargs.c:208
EXPORT void save_args ( int  ac,
av   
)

Definition at line 58 of file saveargs.c.

Referenced by init_arginfo(), and main().

61 {
62  ac_saved = ac;
63  av_saved = av;
64  save_av0(av[0]);
65 }
static char ** av_saved
Definition: saveargs.c:43
static int ac_saved
Definition: saveargs.c:42
LOCAL void save_av0(char *av0)
Definition: saveargs.c:68
LOCAL void save_av0 ( char av0)

Definition at line 68 of file saveargs.c.

Referenced by init_progname(), and save_args().

70 {
71  int slen;
72  char *p;
73 
74  if (av0_saved && av0_saved != av0_sp)
75  free(av0_saved);
76 
77  slen = strlen(av0) + 1;
78 
79  if (slen <= (int)sizeof (av0_sp))
80  av0_saved = 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
#define free
Definition: debug_ros.c:5
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
smooth NULL
Definition: ftsmooth.c:416
static char * av0_saved
Definition: saveargs.c:44
static char av0_sp[32]
Definition: saveargs.c:49
static char * av0_name_saved
Definition: saveargs.c:45
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define malloc
Definition: debug_ros.c:4
GLfloat GLfloat p
Definition: glext.h:8902
EXPORT int saved_ac ( )

Definition at line 96 of file saveargs.c.

Referenced by vers_write().

97 {
98  if (av_saved == NULL)
99  init_arginfo();
100 
101  return (ac_saved);
102 }
static char ** av_saved
Definition: saveargs.c:43
smooth NULL
Definition: ftsmooth.c:416
static int ac_saved
Definition: saveargs.c:42
LOCAL void init_arginfo()
Definition: saveargs.c:208
EXPORT char** saved_av ( )

Definition at line 105 of file saveargs.c.

Referenced by vers_write().

106 {
107  if (av_saved == NULL)
108  init_arginfo();
109 
110  return (av_saved);
111 }
static char ** av_saved
Definition: saveargs.c:43
smooth NULL
Definition: ftsmooth.c:416
LOCAL void init_arginfo()
Definition: saveargs.c:208
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 }
smooth NULL
Definition: ftsmooth.c:416
static char * av0_saved
Definition: saveargs.c:44
LOCAL void init_arginfo()
Definition: saveargs.c:208
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 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define free
Definition: debug_ros.c:5
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
static char prn_sp[32]
Definition: saveargs.c:50
smooth NULL
Definition: ftsmooth.c:416
static char * progname_saved
Definition: saveargs.c:47
Definition: name.c:36
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define malloc
Definition: debug_ros.c:4
GLfloat GLfloat p
Definition: glext.h:8902
static char * progpath_saved
Definition: saveargs.c:46

Variable Documentation

int ac_saved
static

Definition at line 42 of file saveargs.c.

Referenced by save_args(), and saved_ac().

char* av0_name_saved
static

Definition at line 45 of file saveargs.c.

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

char* av0_saved
static

Definition at line 44 of file saveargs.c.

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

char av0_sp[32]
static

Definition at line 49 of file saveargs.c.

Referenced by save_av0().

char** av_saved
static

Definition at line 43 of file saveargs.c.

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

char dfl_str[] = "?"
static

Definition at line 51 of file saveargs.c.

Referenced by get_progname(), and get_progpath().

char prn_sp[32]
static

Definition at line 50 of file saveargs.c.

Referenced by set_progname().

char* progname_saved
static

Definition at line 47 of file saveargs.c.

Referenced by get_progname(), and set_progname().

char* progpath_saved
static

Definition at line 46 of file saveargs.c.

Referenced by get_progpath(), and set_progname().