ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/fixargv0.c
Revision: 2.6
Committed: Sat Mar 19 00:44:46 2016 UTC (8 years, 1 month ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.5: +4 -2 lines
Log Message:
When argv is dynamically allocated, changing the pointer values crashes deallocation (yes, I'm doing weird things).

File Contents

# User Rev Content
1 greg 2.1 #ifndef lint
2 schorsch 2.6 static const char RCSid[] = "$Id: fixargv0.c,v 2.5 2003/10/27 10:19:31 schorsch Exp $";
3 greg 2.1 #endif
4     /*
5     * Fix argv[0] for DOS environments
6 greg 2.2 *
7 schorsch 2.4 * External symbols declared in paths.h
8 greg 2.2 */
9    
10 greg 2.3 #include "copyright.h"
11 greg 2.1
12 schorsch 2.4 #include <ctype.h>
13 schorsch 2.6 #include <string.h>
14 greg 2.1
15 schorsch 2.5 extern char *
16 greg 2.1 fixargv0(av0) /* extract command name from full path */
17     char *av0;
18     {
19     register char *cp = av0;
20    
21     while (*cp) cp++; /* start from end */
22     while (cp-- > av0)
23     switch (*cp) { /* fix up command name */
24     case '.': /* remove extension */
25     *cp = '\0';
26     continue;
27     case '\\': /* remove directory */
28 schorsch 2.6 strcpy(av0, cp+1);
29     break;
30 greg 2.1 default: /* convert to lower case */
31     *cp = tolower(*cp);
32     continue;
33     }
34     return(av0);
35     }
36    
37