www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/04/12/15:34:51

Date: Sat, 13 Apr 1996 03:26:26 -0800 (GMT)
From: "Rafael R. Sevilla" <rsevilla AT upd DOT edu DOT ph>
To: DJGPP newsgroup mail <djgpp AT delorie DOT com>
Subject: DJGPP's strrchr
Message-ID: <Pine.SOL.3.91.960413025317.21320A-100000@sauron>
MIME-Version: 1.0

I've been writing a few programs that get their program name with the path
stripped off them using strrchr to find the last occurrence of '/' or
whatever path separator is used, in argv[0] which is the program name and
path. The code looks a bit like:

#include <string.h>
char *progname;

main(int argc, char *argv[]) {
	if ((progname = strrchr(argv[0], '/')) == NULL)
		progname = argv[0];
	else
		progname++;
	...
}

In Unix (GCC 2.7.2 also), Turbo C 2.0, and Watcom C 9.0 this expression
compiles fine, with all warnings turned on (changing the '/' to '\\' for
Turbo and Watcom of course). But under djgpp this expression causes a
cryptic warning: "assignment converts integer to pointer without cast" on
the line containing the 'if'. If I understand this correctly, the compiler
thinks that strrchr should return an integer, rather than a character
pointer, since this is the only assignment I've got on that line. But why?
The C standard says it should return a pointer to the last character
found. The declaration for strrchr in string.h file looks right. Is this a
bug in the port or something? The SunOS 5.3 GCC I use which is precisely
the same version as the djgpp port has no problems with these statements.
What's going on? Should I just ignore the warning? From experience
warnings like that usually lead to GP faults and other unpleasant
occurrences, especially when dealing with pointers. 

Another, unrelated question: when passing full pathnames to djgpp programs
what path separator should be used? The traditional DOS backslash or the
Unix-style forward slash? The djgpp programs seem to deal with full
pathnames in a rather confused and inconsistent manner.

-------------------------------------------------------------------------
University of the Philippines                           Rafael R. Sevilla
PABX/OVCA: Diliman Networking Project          rsevilla AT sauron DOT upd DOT edu DOT ph
-------------------------------------------------------------------------



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019