Mercurial > code
comparison C/port/setprogname.c @ 334:0b576ee64d45
* Create brand new hierarchy
* Rename DynLib to Dynlib
* Remove some warnings
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sun, 08 Mar 2015 14:26:33 +0100 |
parents | port/setprogname.c@1513cf3a985e |
children |
comparison
equal
deleted
inserted
replaced
333:412ca7a5e1ea | 334:0b576ee64d45 |
---|---|
1 /* | |
2 * setprogname.c -- get or set the program name | |
3 * | |
4 * Copyright (c) 2011, 2012 David Demelier <markand@malikania.fr> | |
5 * | |
6 * Permission to use, copy, modify, and/or distribute this software for any | |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
9 * | |
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 */ | |
18 | |
19 #include <stdio.h> | |
20 #include <stdlib.h> | |
21 #include <string.h> | |
22 | |
23 /* | |
24 * Do not return NULL if the developer didn't call setprogname to | |
25 * prevent useless segfault. | |
26 */ | |
27 static const char *g_pname = ""; | |
28 | |
29 void | |
30 setprogname(const char *progname) | |
31 { | |
32 const char *p; | |
33 | |
34 /* Seek last / or \ on windows */ | |
35 if ((p = strrchr(progname, '/')) || (p = strrchr(progname, '\\'))) | |
36 g_pname = &p[1]; | |
37 else | |
38 g_pname = progname; | |
39 } | |
40 | |
41 const char * | |
42 getprogname(void) | |
43 { | |
44 return g_pname; | |
45 } |