mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Put back getopt for MingW
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/branches/freeze_1_8_0@17701 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
9983258a29
commit
00dfac3ed2
2 changed files with 71 additions and 4 deletions
|
@ -3,9 +3,6 @@
|
|||
* Tools/cvtenc.m (main): Write using local/set encoding when
|
||||
EscapeIn=YES.
|
||||
|
||||
* Tools/gdomap.c: Remove getopt function for MinGW
|
||||
(patch from Leigh Smith <leigh@leighsmith.com>).
|
||||
|
||||
* Documentation/coding-standards.texi: Add section about object
|
||||
persistance.
|
||||
|
||||
|
|
|
@ -177,6 +177,76 @@ static void queue_probe(struct in_addr* to, struct in_addr *from,
|
|||
int num_extras, struct in_addr* extra, int is_reply);
|
||||
|
||||
|
||||
#ifdef __MINGW__
|
||||
|
||||
/* A simple implementation of getopt() */
|
||||
|
||||
static int
|
||||
indexof(char c, char *string)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < strlen(string); i++)
|
||||
{
|
||||
if (string[i] == c)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static char *optarg;
|
||||
|
||||
static char
|
||||
getopt(int argc, char **argv, char *options)
|
||||
{
|
||||
static int argi;
|
||||
static char *arg;
|
||||
int index;
|
||||
char retval = '\0';
|
||||
|
||||
optarg = NULL;
|
||||
if (argi == 0)
|
||||
{
|
||||
argi = 1;
|
||||
}
|
||||
while (argi < argc)
|
||||
{
|
||||
arg = argv[argi];
|
||||
if (strlen(arg) == 2)
|
||||
{
|
||||
if (arg[0] == '-')
|
||||
{
|
||||
if ((index = indexof(arg[1], options)) != -1)
|
||||
{
|
||||
retval = arg[1];
|
||||
if (index < strlen(options))
|
||||
{
|
||||
if (options[index+1] == ':')
|
||||
{
|
||||
if (argi < argc-1)
|
||||
{
|
||||
argi++;
|
||||
optarg = argv[argi];
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1; /* ':' given, but argv exhausted */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
argi++;
|
||||
return retval;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static char ebuf[2048];
|
||||
|
||||
|
||||
|
@ -4532,13 +4602,13 @@ printf(
|
|||
/*
|
||||
* As another level of paranoia - restrict this process to /tmp
|
||||
*/
|
||||
#ifndef __MINGW__
|
||||
if (chdir("/tmp") < 0)
|
||||
{
|
||||
sprintf(ebuf, "Unable to change directory to /tmp");
|
||||
gdomap_log(LOG_CRIT);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#ifndef __MINGW__
|
||||
if (geteuid() == 0)
|
||||
{
|
||||
if (chroot("/tmp") < 0)
|
||||
|
|
Loading…
Reference in a new issue