1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
27 * return the full path of the current program in path
28 * command!=0 is used as a default
34 #include <ast_windows.h>
38 #include "FEATURE/prog"
41 prog(const char* command
, char* path
, size_t size
)
44 #if _WINIX || _lib_getexecname
55 if ((n
= readlink(_PROC_PROG
, path
, size
)) > 0)
63 if (s
= (char*)getexecname())
72 if (s
= GetCommandLine())
82 else if (!q
&& c
== '"')
84 else if (!q
&& isspace(c
))
87 *t
++ = c
== '\\' ? '/' : c
;
93 return (t
- path
) + n
;
98 if ((n
= strlen(command
) + 1) <= size
)
99 memcpy(path
, command
, n
);
106 pathprog(const char* command
, char* path
, size_t size
)
111 if ((n
= prog(command
, path
, size
)) > 0 && n
<= size
&& *path
!= '/')
113 if (!pathpath(buf
, path
, NiL
, PATH_REGULAR
|PATH_EXECUTE
))
115 else if ((n
= strlen(buf
) + 1) <= size
)
116 memcpy(path
, buf
, n
);