Archive-Unzip-Burst
view release on metacpan or search on metacpan
unzip-6.0/theos/_setargv.c view on Meta::CPAN
/*
Copyright (c) 1990-2001 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2000-Apr-09 or later
(the contents of which are also included in unzip.h) for terms of use.
If, for some reason, all these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
/*
* _setargv.c - derived from an command argument expander
*
* Author : Jean-Michel Dubois
* Date : 13-Dec-98
*
* Function: Looks for member names (fn.ft.mb) and add the libraries names
* (fn.ft) to the list of files to zip to force inclusion of
* libraries if necessary.
* Strings beginning by a dash are considered as options and left
* unchanged.
*
* Syntax : void _setargv(int *argc, char ***argv);
*
* Returns : new argc. Caller's argc and argv are updated.
* If a insufficient memory condition occurs, return 0 and errno
* is set to ENOMEM.
*
* Example :
* main(int argc, char **argv)
* {
* if (_setargv(&argc, &argv)) {
* ...
*/
#pragma library
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <errno.h>
#include <scr.h>
#include <peek.h>
/* Allocate argv array in 16 entries chunks */
static int allocarg(int n, int asize, char ***nargv, char *s)
{
if ((n+1) > asize) { /* If array full */
asize += 16; /* increase size and reallocate */
if (!(*nargv = (char **) realloc(*nargv, asize * sizeof (void *)))) {
errno = _errnum = ENOMEM; /* Not enough memory */
return 0;
}
}
(*nargv)[n] = strdup(s); /* Save argument */
return asize; /* Return new maxsize */
}
/* check if file is a member of a library */
static int ismember(char* path)
{
char* p;
if ((p = strrchr(path, '/')) == NULL)
p = path;
return ((p = strchr(p, '.')) && (p = strchr(p + 1, '.')));
}
/* extract library name from a file name */
static char* libname(char* path)
{
char* p;
static char lib[256];
char disk[3];
strcpy(lib, path);
if (p = strrchr(lib, ':')) {
strncpy(disk, p, 2);
disk[2] = '\0';
*p = '\0' ;
} else
disk[0] = '\0';
( run in 1.199 second using v1.01-cache-2.11-cpan-c221a9de4ec )