mirror of
https://github.com/mirror/make.git
synced 2025-02-05 01:00:11 +08:00
updated w32 code by tulloh
This commit is contained in:
parent
561b384313
commit
fc47a2c83c
@ -1,3 +1,11 @@
|
||||
Fri Jul 19 16:57:27 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
|
||||
|
||||
* GNUmakefile (win32files): New variable.
|
||||
(distfiles): Add it.
|
||||
* w32: Updated by Rob Tulloh.
|
||||
|
||||
* makefile.vms (LOADLIBES): Fix typo.
|
||||
|
||||
Sun Jul 14 12:59:27 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
|
||||
|
||||
* job.c (construct_command_argv_internal): Fix up #else, #endifs.
|
||||
|
@ -1,188 +1,188 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "dirent.h"
|
||||
|
||||
|
||||
DIR*
|
||||
opendir(const char* pDirName)
|
||||
{
|
||||
struct stat sb;
|
||||
DIR* pDir;
|
||||
char* pEndDirName;
|
||||
int nBufferLen;
|
||||
|
||||
/* sanity checks */
|
||||
if (!pDirName) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
if (stat(pDirName, &sb) != 0) {
|
||||
errno = ENOENT;
|
||||
return NULL;
|
||||
}
|
||||
if ((sb.st_mode & S_IFMT) != S_IFDIR) {
|
||||
errno = ENOTDIR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* allocate a DIR structure to return */
|
||||
pDir = (DIR *) malloc(sizeof (DIR));
|
||||
|
||||
if (!pDir)
|
||||
return NULL;
|
||||
|
||||
/* input directory name length */
|
||||
nBufferLen = strlen(pDirName);
|
||||
|
||||
/* copy input directory name to DIR buffer */
|
||||
strcpy(pDir->dir_pDirectoryName, pDirName);
|
||||
|
||||
/* point to end of the copied directory name */
|
||||
pEndDirName = &pDir->dir_pDirectoryName[nBufferLen - 1];
|
||||
|
||||
/* if directory name did not end in '/' or '\', add '/' */
|
||||
if ((*pEndDirName != '/') && (*pEndDirName != '\\')) {
|
||||
pEndDirName++;
|
||||
*pEndDirName = '/';
|
||||
}
|
||||
|
||||
/* now append the wildcard character to the buffer */
|
||||
pEndDirName++;
|
||||
*pEndDirName = '*';
|
||||
pEndDirName++;
|
||||
*pEndDirName = '\0';
|
||||
|
||||
/* other values defaulted */
|
||||
pDir->dir_nNumFiles = 0;
|
||||
pDir->dir_hDirHandle = INVALID_HANDLE_VALUE;
|
||||
pDir->dir_ulCookie = __DIRENT_COOKIE;
|
||||
|
||||
return pDir;
|
||||
}
|
||||
|
||||
void
|
||||
closedir(DIR *pDir)
|
||||
{
|
||||
/* got a valid pointer? */
|
||||
if (!pDir) {
|
||||
errno = EINVAL;
|
||||
return;
|
||||
}
|
||||
|
||||
/* sanity check that this is a DIR pointer */
|
||||
if (pDir->dir_ulCookie != __DIRENT_COOKIE) {
|
||||
errno = EINVAL;
|
||||
return;
|
||||
}
|
||||
|
||||
/* close the WIN32 directory handle */
|
||||
if (pDir->dir_hDirHandle != INVALID_HANDLE_VALUE)
|
||||
FindClose(pDir->dir_hDirHandle);
|
||||
|
||||
free(pDir);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
struct dirent *
|
||||
readdir(DIR* pDir)
|
||||
{
|
||||
WIN32_FIND_DATA wfdFindData;
|
||||
|
||||
if (!pDir) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* sanity check that this is a DIR pointer */
|
||||
if (pDir->dir_ulCookie != __DIRENT_COOKIE) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pDir->dir_nNumFiles == 0) {
|
||||
pDir->dir_hDirHandle = FindFirstFile(pDir->dir_pDirectoryName, &wfdFindData);
|
||||
if (pDir->dir_hDirHandle == INVALID_HANDLE_VALUE)
|
||||
return NULL;
|
||||
} else if (!FindNextFile(pDir->dir_hDirHandle, &wfdFindData))
|
||||
return NULL;
|
||||
|
||||
/* bump count for next call to readdir() or telldir() */
|
||||
pDir->dir_nNumFiles++;
|
||||
|
||||
/* fill in struct dirent values */
|
||||
pDir->dir_sdReturn.d_ino = -1;
|
||||
strcpy(pDir->dir_sdReturn.d_name, wfdFindData.cFileName);
|
||||
|
||||
return &pDir->dir_sdReturn;
|
||||
}
|
||||
|
||||
void
|
||||
rewinddir(DIR* pDir)
|
||||
{
|
||||
if (!pDir) {
|
||||
errno = EINVAL;
|
||||
return;
|
||||
}
|
||||
|
||||
/* sanity check that this is a DIR pointer */
|
||||
if (pDir->dir_ulCookie != __DIRENT_COOKIE) {
|
||||
errno = EINVAL;
|
||||
return;
|
||||
}
|
||||
|
||||
/* close the WIN32 directory handle */
|
||||
if (pDir->dir_hDirHandle != INVALID_HANDLE_VALUE)
|
||||
if (!FindClose(pDir->dir_hDirHandle))
|
||||
errno = EBADF;
|
||||
|
||||
/* reset members which control readdir() */
|
||||
pDir->dir_hDirHandle = INVALID_HANDLE_VALUE;
|
||||
pDir->dir_nNumFiles = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int
|
||||
telldir(DIR* pDir)
|
||||
{
|
||||
if (!pDir) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* sanity check that this is a DIR pointer */
|
||||
if (pDir->dir_ulCookie != __DIRENT_COOKIE) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* return number of times readdir() called */
|
||||
return pDir->dir_nNumFiles;
|
||||
}
|
||||
|
||||
void
|
||||
seekdir(DIR* pDir, long nPosition)
|
||||
{
|
||||
if (!pDir)
|
||||
return;
|
||||
|
||||
/* sanity check that this is a DIR pointer */
|
||||
if (pDir->dir_ulCookie != __DIRENT_COOKIE)
|
||||
return;
|
||||
|
||||
/* go back to beginning of directory */
|
||||
rewinddir(pDir);
|
||||
|
||||
/* loop until we have found position we care about */
|
||||
for (--nPosition; nPosition && readdir(pDir); nPosition--);
|
||||
|
||||
/* flag invalid nPosition value */
|
||||
if (nPosition)
|
||||
errno = EINVAL;
|
||||
|
||||
return;
|
||||
}
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "dirent.h"
|
||||
|
||||
|
||||
DIR*
|
||||
opendir(const char* pDirName)
|
||||
{
|
||||
struct stat sb;
|
||||
DIR* pDir;
|
||||
char* pEndDirName;
|
||||
int nBufferLen;
|
||||
|
||||
/* sanity checks */
|
||||
if (!pDirName) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
if (stat(pDirName, &sb) != 0) {
|
||||
errno = ENOENT;
|
||||
return NULL;
|
||||
}
|
||||
if ((sb.st_mode & S_IFMT) != S_IFDIR) {
|
||||
errno = ENOTDIR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* allocate a DIR structure to return */
|
||||
pDir = (DIR *) malloc(sizeof (DIR));
|
||||
|
||||
if (!pDir)
|
||||
return NULL;
|
||||
|
||||
/* input directory name length */
|
||||
nBufferLen = strlen(pDirName);
|
||||
|
||||
/* copy input directory name to DIR buffer */
|
||||
strcpy(pDir->dir_pDirectoryName, pDirName);
|
||||
|
||||
/* point to end of the copied directory name */
|
||||
pEndDirName = &pDir->dir_pDirectoryName[nBufferLen - 1];
|
||||
|
||||
/* if directory name did not end in '/' or '\', add '/' */
|
||||
if ((*pEndDirName != '/') && (*pEndDirName != '\\')) {
|
||||
pEndDirName++;
|
||||
*pEndDirName = '/';
|
||||
}
|
||||
|
||||
/* now append the wildcard character to the buffer */
|
||||
pEndDirName++;
|
||||
*pEndDirName = '*';
|
||||
pEndDirName++;
|
||||
*pEndDirName = '\0';
|
||||
|
||||
/* other values defaulted */
|
||||
pDir->dir_nNumFiles = 0;
|
||||
pDir->dir_hDirHandle = INVALID_HANDLE_VALUE;
|
||||
pDir->dir_ulCookie = __DIRENT_COOKIE;
|
||||
|
||||
return pDir;
|
||||
}
|
||||
|
||||
void
|
||||
closedir(DIR *pDir)
|
||||
{
|
||||
/* got a valid pointer? */
|
||||
if (!pDir) {
|
||||
errno = EINVAL;
|
||||
return;
|
||||
}
|
||||
|
||||
/* sanity check that this is a DIR pointer */
|
||||
if (pDir->dir_ulCookie != __DIRENT_COOKIE) {
|
||||
errno = EINVAL;
|
||||
return;
|
||||
}
|
||||
|
||||
/* close the WIN32 directory handle */
|
||||
if (pDir->dir_hDirHandle != INVALID_HANDLE_VALUE)
|
||||
FindClose(pDir->dir_hDirHandle);
|
||||
|
||||
free(pDir);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
struct dirent *
|
||||
readdir(DIR* pDir)
|
||||
{
|
||||
WIN32_FIND_DATA wfdFindData;
|
||||
|
||||
if (!pDir) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* sanity check that this is a DIR pointer */
|
||||
if (pDir->dir_ulCookie != __DIRENT_COOKIE) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pDir->dir_nNumFiles == 0) {
|
||||
pDir->dir_hDirHandle = FindFirstFile(pDir->dir_pDirectoryName, &wfdFindData);
|
||||
if (pDir->dir_hDirHandle == INVALID_HANDLE_VALUE)
|
||||
return NULL;
|
||||
} else if (!FindNextFile(pDir->dir_hDirHandle, &wfdFindData))
|
||||
return NULL;
|
||||
|
||||
/* bump count for next call to readdir() or telldir() */
|
||||
pDir->dir_nNumFiles++;
|
||||
|
||||
/* fill in struct dirent values */
|
||||
pDir->dir_sdReturn.d_ino = -1;
|
||||
strcpy(pDir->dir_sdReturn.d_name, wfdFindData.cFileName);
|
||||
|
||||
return &pDir->dir_sdReturn;
|
||||
}
|
||||
|
||||
void
|
||||
rewinddir(DIR* pDir)
|
||||
{
|
||||
if (!pDir) {
|
||||
errno = EINVAL;
|
||||
return;
|
||||
}
|
||||
|
||||
/* sanity check that this is a DIR pointer */
|
||||
if (pDir->dir_ulCookie != __DIRENT_COOKIE) {
|
||||
errno = EINVAL;
|
||||
return;
|
||||
}
|
||||
|
||||
/* close the WIN32 directory handle */
|
||||
if (pDir->dir_hDirHandle != INVALID_HANDLE_VALUE)
|
||||
if (!FindClose(pDir->dir_hDirHandle))
|
||||
errno = EBADF;
|
||||
|
||||
/* reset members which control readdir() */
|
||||
pDir->dir_hDirHandle = INVALID_HANDLE_VALUE;
|
||||
pDir->dir_nNumFiles = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int
|
||||
telldir(DIR* pDir)
|
||||
{
|
||||
if (!pDir) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* sanity check that this is a DIR pointer */
|
||||
if (pDir->dir_ulCookie != __DIRENT_COOKIE) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* return number of times readdir() called */
|
||||
return pDir->dir_nNumFiles;
|
||||
}
|
||||
|
||||
void
|
||||
seekdir(DIR* pDir, long nPosition)
|
||||
{
|
||||
if (!pDir)
|
||||
return;
|
||||
|
||||
/* sanity check that this is a DIR pointer */
|
||||
if (pDir->dir_ulCookie != __DIRENT_COOKIE)
|
||||
return;
|
||||
|
||||
/* go back to beginning of directory */
|
||||
rewinddir(pDir);
|
||||
|
||||
/* loop until we have found position we care about */
|
||||
for (--nPosition; nPosition && readdir(pDir); nPosition--);
|
||||
|
||||
/* flag invalid nPosition value */
|
||||
if (nPosition)
|
||||
errno = EINVAL;
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -1,37 +1,37 @@
|
||||
#ifndef _DIRENT_H
|
||||
#define _DIRENT_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
#include <limits.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifndef NAME_MAX
|
||||
#define NAME_MAX 255
|
||||
#endif
|
||||
|
||||
#define __DIRENT_COOKIE 0xfefeabab
|
||||
|
||||
|
||||
struct dirent
|
||||
{
|
||||
ino_t d_ino; /* unused - no equivalent on WIN32 */
|
||||
char d_name[NAME_MAX+1];
|
||||
};
|
||||
|
||||
typedef struct dir_struct {
|
||||
ULONG dir_ulCookie;
|
||||
HANDLE dir_hDirHandle;
|
||||
DWORD dir_nNumFiles;
|
||||
char dir_pDirectoryName[NAME_MAX+1];
|
||||
struct dirent dir_sdReturn;
|
||||
} DIR;
|
||||
|
||||
DIR *opendir(const char *);
|
||||
struct dirent *readdir(DIR *);
|
||||
void rewinddir(DIR *);
|
||||
void closedir(DIR *);
|
||||
int telldir(DIR *);
|
||||
void seekdir(DIR *, long);
|
||||
|
||||
#endif
|
||||
#ifndef _DIRENT_H
|
||||
#define _DIRENT_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
#include <limits.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifndef NAME_MAX
|
||||
#define NAME_MAX 255
|
||||
#endif
|
||||
|
||||
#define __DIRENT_COOKIE 0xfefeabab
|
||||
|
||||
|
||||
struct dirent
|
||||
{
|
||||
ino_t d_ino; /* unused - no equivalent on WIN32 */
|
||||
char d_name[NAME_MAX+1];
|
||||
};
|
||||
|
||||
typedef struct dir_struct {
|
||||
ULONG dir_ulCookie;
|
||||
HANDLE dir_hDirHandle;
|
||||
DWORD dir_nNumFiles;
|
||||
char dir_pDirectoryName[NAME_MAX+1];
|
||||
struct dirent dir_sdReturn;
|
||||
} DIR;
|
||||
|
||||
DIR *opendir(const char *);
|
||||
struct dirent *readdir(DIR *);
|
||||
void rewinddir(DIR *);
|
||||
void closedir(DIR *);
|
||||
int telldir(DIR *);
|
||||
void seekdir(DIR *, long);
|
||||
|
||||
#endif
|
||||
|
@ -1,10 +1,10 @@
|
||||
#ifndef _PATHSTUFF_H
|
||||
#define _PATHSTUFF_H
|
||||
|
||||
extern char * convert_Path_to_win32(char *Path, char to_delim);
|
||||
extern char * w32ify(char *file, int resolve);
|
||||
extern char * getcwd_fs(char *buf, int len);
|
||||
|
||||
#define convert_vpath_to_win32(vpath, delim) convert_Path_to_win32(vpath, delim)
|
||||
|
||||
#endif
|
||||
#ifndef _PATHSTUFF_H
|
||||
#define _PATHSTUFF_H
|
||||
|
||||
extern char * convert_Path_to_win32(char *Path, char to_delim);
|
||||
extern char * w32ify(char *file, int resolve);
|
||||
extern char * getcwd_fs(char *buf, int len);
|
||||
|
||||
#define convert_vpath_to_win32(vpath, delim) convert_Path_to_win32(vpath, delim)
|
||||
|
||||
#endif
|
||||
|
@ -1,54 +1,54 @@
|
||||
#ifndef SUB_PROC_H
|
||||
#define SUB_PROC_H
|
||||
|
||||
/*
|
||||
* Component Name:
|
||||
*
|
||||
* $Date$
|
||||
*
|
||||
* $Source$
|
||||
*
|
||||
* $Revision$
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
* (C) COPYRIGHT TIVOLI Systems, Inc. 1991-1994
|
||||
* Unpublished Work
|
||||
* All Rights Reserved
|
||||
* Licensed Material - Property of TIVOLI Systems, Inc.
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#define EXTERN_DECL(entry, args) extern entry args
|
||||
#define VOID_DECL void
|
||||
|
||||
EXTERN_DECL(HANDLE process_init, (VOID_DECL));
|
||||
EXTERN_DECL(HANDLE process_init_fd, (HANDLE stdinh, HANDLE stdouth,
|
||||
HANDLE stderrh));
|
||||
EXTERN_DECL(long process_begin, (HANDLE proc, char **argv, char **envp,
|
||||
char *exec_path, char *as_user));
|
||||
EXTERN_DECL(long process_pipe_io, (HANDLE proc, char *stdin_data,
|
||||
int stdin_data_len));
|
||||
EXTERN_DECL(long process_file_io, (HANDLE proc));
|
||||
EXTERN_DECL(void process_cleanup, (HANDLE proc));
|
||||
EXTERN_DECL(HANDLE process_wait_for_any, (VOID_DECL));
|
||||
EXTERN_DECL(void process_register, (HANDLE proc));
|
||||
EXTERN_DECL(HANDLE process_easy, (char** argv, char** env));
|
||||
EXTERN_DECL(BOOL process_kill, (HANDLE proc, int signal));
|
||||
|
||||
/* support routines */
|
||||
EXTERN_DECL(long process_errno, (HANDLE proc));
|
||||
EXTERN_DECL(long process_last_err, (HANDLE proc));
|
||||
EXTERN_DECL(long process_exit_code, (HANDLE proc));
|
||||
EXTERN_DECL(long process_signal, (HANDLE proc));
|
||||
EXTERN_DECL(char * process_outbuf, (HANDLE proc));
|
||||
EXTERN_DECL(char * process_errbuf, (HANDLE proc));
|
||||
EXTERN_DECL(int process_outcnt, (HANDLE proc));
|
||||
EXTERN_DECL(int process_errcnt, (HANDLE proc));
|
||||
EXTERN_DECL(void process_pipes, (HANDLE proc, int pipes[3]));
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#ifndef SUB_PROC_H
|
||||
#define SUB_PROC_H
|
||||
|
||||
/*
|
||||
* Component Name:
|
||||
*
|
||||
* $Date$
|
||||
*
|
||||
* $Source$
|
||||
*
|
||||
* $Revision$
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
* (C) COPYRIGHT TIVOLI Systems, Inc. 1991-1994
|
||||
* Unpublished Work
|
||||
* All Rights Reserved
|
||||
* Licensed Material - Property of TIVOLI Systems, Inc.
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#define EXTERN_DECL(entry, args) extern entry args
|
||||
#define VOID_DECL void
|
||||
|
||||
EXTERN_DECL(HANDLE process_init, (VOID_DECL));
|
||||
EXTERN_DECL(HANDLE process_init_fd, (HANDLE stdinh, HANDLE stdouth,
|
||||
HANDLE stderrh));
|
||||
EXTERN_DECL(long process_begin, (HANDLE proc, char **argv, char **envp,
|
||||
char *exec_path, char *as_user));
|
||||
EXTERN_DECL(long process_pipe_io, (HANDLE proc, char *stdin_data,
|
||||
int stdin_data_len));
|
||||
EXTERN_DECL(long process_file_io, (HANDLE proc));
|
||||
EXTERN_DECL(void process_cleanup, (HANDLE proc));
|
||||
EXTERN_DECL(HANDLE process_wait_for_any, (VOID_DECL));
|
||||
EXTERN_DECL(void process_register, (HANDLE proc));
|
||||
EXTERN_DECL(HANDLE process_easy, (char** argv, char** env));
|
||||
EXTERN_DECL(BOOL process_kill, (HANDLE proc, int signal));
|
||||
|
||||
/* support routines */
|
||||
EXTERN_DECL(long process_errno, (HANDLE proc));
|
||||
EXTERN_DECL(long process_last_err, (HANDLE proc));
|
||||
EXTERN_DECL(long process_exit_code, (HANDLE proc));
|
||||
EXTERN_DECL(long process_signal, (HANDLE proc));
|
||||
EXTERN_DECL(char * process_outbuf, (HANDLE proc));
|
||||
EXTERN_DECL(char * process_errbuf, (HANDLE proc));
|
||||
EXTERN_DECL(int process_outcnt, (HANDLE proc));
|
||||
EXTERN_DECL(int process_errcnt, (HANDLE proc));
|
||||
EXTERN_DECL(void process_pipes, (HANDLE proc, int pipes[3]));
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -1,10 +1,10 @@
|
||||
#ifndef _W32ERR_H_
|
||||
#define _W32ERR_H_
|
||||
|
||||
#ifndef EXTERN_DECL
|
||||
#define EXTERN_DECL(entry, args) entry args
|
||||
#endif
|
||||
|
||||
EXTERN_DECL(char * map_win32_error_to_string, (DWORD error));
|
||||
|
||||
#endif /* !_W32ERR_H */
|
||||
#ifndef _W32ERR_H_
|
||||
#define _W32ERR_H_
|
||||
|
||||
#ifndef EXTERN_DECL
|
||||
#define EXTERN_DECL(entry, args) entry args
|
||||
#endif
|
||||
|
||||
EXTERN_DECL(char * map_win32_error_to_string, (DWORD error));
|
||||
|
||||
#endif /* !_W32ERR_H */
|
||||
|
438
w32/pathstuff.c
438
w32/pathstuff.c
@ -1,219 +1,219 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "make.h"
|
||||
|
||||
/*
|
||||
* Convert delimiter separated path to Canonical format.
|
||||
*/
|
||||
char *
|
||||
convert_Path_to_win32(char *Path, char to_delim)
|
||||
{
|
||||
char *etok; /* token separator for old Path */
|
||||
char *p; /* points to element of old Path */
|
||||
|
||||
/* is this a multi-element Path ? */
|
||||
for (p = Path, etok = strpbrk(p, ":;");
|
||||
etok;
|
||||
etok = strpbrk(p, ":;"))
|
||||
if ((etok - p) == 1) {
|
||||
if (*(etok - 1) == ';' ||
|
||||
*(etok - 1) == ':') {
|
||||
etok[-1] = to_delim;
|
||||
etok[0] = to_delim;
|
||||
p = ++etok;
|
||||
continue; /* ignore empty bucket */
|
||||
} else if (etok = strpbrk(etok+1, ":;")) {
|
||||
/* found one to count, handle drive letter */
|
||||
*etok = to_delim;
|
||||
p = ++etok;
|
||||
} else
|
||||
/* all finished, force abort */
|
||||
p += strlen(p);
|
||||
} else {
|
||||
/* found another one, no drive letter */
|
||||
*etok = to_delim;
|
||||
p = ++etok;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* convert to backward slashes */
|
||||
for (p = Path, p = strchr(p, '/'); p; p = strchr(p, '/'))
|
||||
*p = '\\';
|
||||
#endif
|
||||
return Path;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert to forward slashes. Resolve to full pathname optionally
|
||||
*/
|
||||
char *
|
||||
w32ify(char *filename, int resolve)
|
||||
{
|
||||
static char w32_path[FILENAME_MAX];
|
||||
char *p;
|
||||
|
||||
if (resolve)
|
||||
_fullpath(w32_path, filename, sizeof (w32_path));
|
||||
else
|
||||
strncpy(w32_path, filename, sizeof (w32_path));
|
||||
|
||||
for (p = w32_path; p && *p; p++)
|
||||
if (*p == '\\')
|
||||
*p = '/';
|
||||
|
||||
return w32_path;
|
||||
}
|
||||
|
||||
char *
|
||||
getcwd_fs(char* buf, int len)
|
||||
{
|
||||
char *p;
|
||||
|
||||
if (p = getcwd(buf, len)) {
|
||||
char *q = w32ify(buf, 0);
|
||||
strncpy(buf, q, len);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
#ifdef unused
|
||||
/*
|
||||
* Convert delimiter separated pathnames (e.g. PATH) or single file pathname
|
||||
* (e.g. c:/foo, c:\bar) to NutC format. If we are handed a string that
|
||||
* _NutPathToNutc() fails to convert, just return the path we were handed
|
||||
* and assume the caller will know what to do with it (It was probably
|
||||
* a mistake to try and convert it anyway due to some of the bizarre things
|
||||
* that might look like pathnames in makefiles).
|
||||
*/
|
||||
char *
|
||||
convert_path_to_nutc(char *path)
|
||||
{
|
||||
int count; /* count of path elements */
|
||||
char *nutc_path; /* new NutC path */
|
||||
int nutc_path_len; /* length of buffer to allocate for new path */
|
||||
char *pathp; /* pointer to nutc_path used to build it */
|
||||
char *etok; /* token separator for old path */
|
||||
char *p; /* points to element of old path */
|
||||
char sep; /* what flavor of separator used in old path */
|
||||
char *rval;
|
||||
|
||||
/* is this a multi-element path ? */
|
||||
for (p = path, etok = strpbrk(p, ":;"), count = 0;
|
||||
etok;
|
||||
etok = strpbrk(p, ":;"))
|
||||
if ((etok - p) == 1) {
|
||||
if (*(etok - 1) == ';' ||
|
||||
*(etok - 1) == ':') {
|
||||
p = ++etok;
|
||||
continue; /* ignore empty bucket */
|
||||
} else if (etok = strpbrk(etok+1, ":;"))
|
||||
/* found one to count, handle drive letter */
|
||||
p = ++etok, count++;
|
||||
else
|
||||
/* all finished, force abort */
|
||||
p += strlen(p);
|
||||
} else
|
||||
/* found another one, no drive letter */
|
||||
p = ++etok, count++;
|
||||
|
||||
if (count) {
|
||||
count++; /* x1;x2;x3 <- need to count x3 */
|
||||
|
||||
/*
|
||||
* Hazard a guess on how big the buffer needs to be.
|
||||
* We have to convert things like c:/foo to /c=/foo.
|
||||
*/
|
||||
nutc_path_len = strlen(path) + (count*2) + 1;
|
||||
nutc_path = xmalloc(nutc_path_len);
|
||||
pathp = nutc_path;
|
||||
*pathp = '\0';
|
||||
|
||||
/*
|
||||
* Loop through PATH and convert one elemnt of the path at at
|
||||
* a time. Single file pathnames will fail this and fall
|
||||
* to the logic below loop.
|
||||
*/
|
||||
for (p = path, etok = strpbrk(p, ":;");
|
||||
etok;
|
||||
etok = strpbrk(p, ":;")) {
|
||||
|
||||
/* don't trip up on device specifiers or empty path slots */
|
||||
if ((etok - p) == 1)
|
||||
if (*(etok - 1) == ';' ||
|
||||
*(etok - 1) == ':') {
|
||||
p = ++etok;
|
||||
continue;
|
||||
} else if ((etok = strpbrk(etok+1, ":;")) == NULL)
|
||||
break; /* thing found was a WIN32 pathname */
|
||||
|
||||
/* save separator */
|
||||
sep = *etok;
|
||||
|
||||
/* terminate the current path element -- temporarily */
|
||||
*etok = '\0';
|
||||
|
||||
#ifdef __NUTC__
|
||||
/* convert to NutC format */
|
||||
if (_NutPathToNutc(p, pathp, 0) == FALSE) {
|
||||
free(nutc_path);
|
||||
rval = savestring(path, strlen(path));
|
||||
return rval;
|
||||
}
|
||||
#else
|
||||
*pathp++ = '/';
|
||||
*pathp++ = p[0];
|
||||
*pathp++ = '=';
|
||||
*pathp++ = '/';
|
||||
strcpy(pathp, &p[2]);
|
||||
#endif
|
||||
|
||||
pathp += strlen(pathp);
|
||||
*pathp++ = ':'; /* use Unix style path separtor for new path */
|
||||
*pathp = '\0'; /* make sure we are null terminaed */
|
||||
|
||||
/* restore path separator */
|
||||
*etok = sep;
|
||||
|
||||
/* point p to first char of next path element */
|
||||
p = ++etok;
|
||||
|
||||
}
|
||||
} else {
|
||||
nutc_path_len = strlen(path) + 3;
|
||||
nutc_path = xmalloc(nutc_path_len);
|
||||
pathp = nutc_path;
|
||||
*pathp = '\0';
|
||||
p = path;
|
||||
}
|
||||
|
||||
/*
|
||||
* OK, here we handle the last element in PATH (e.g. c of a;b;c)
|
||||
* or the path was a single filename and will be converted
|
||||
* here. Note, testing p here assures that we don't trip up
|
||||
* on paths like a;b; which have trailing delimiter followed by
|
||||
* nothing.
|
||||
*/
|
||||
if (*p != '\0') {
|
||||
#ifdef __NUTC__
|
||||
if (_NutPathToNutc(p, pathp, 0) == FALSE) {
|
||||
free(nutc_path);
|
||||
rval = savestring(path, strlen(path));
|
||||
return rval;
|
||||
}
|
||||
#else
|
||||
*pathp++ = '/';
|
||||
*pathp++ = p[0];
|
||||
*pathp++ = '=';
|
||||
*pathp++ = '/';
|
||||
strcpy(pathp, &p[2]);
|
||||
#endif
|
||||
} else
|
||||
*(pathp-1) = '\0'; /* we're already done, don't leave trailing : */
|
||||
|
||||
rval = savestring(nutc_path, strlen(nutc_path));
|
||||
free(nutc_path);
|
||||
return rval;
|
||||
}
|
||||
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "make.h"
|
||||
|
||||
/*
|
||||
* Convert delimiter separated path to Canonical format.
|
||||
*/
|
||||
char *
|
||||
convert_Path_to_win32(char *Path, char to_delim)
|
||||
{
|
||||
char *etok; /* token separator for old Path */
|
||||
char *p; /* points to element of old Path */
|
||||
|
||||
/* is this a multi-element Path ? */
|
||||
for (p = Path, etok = strpbrk(p, ":;");
|
||||
etok;
|
||||
etok = strpbrk(p, ":;"))
|
||||
if ((etok - p) == 1) {
|
||||
if (*(etok - 1) == ';' ||
|
||||
*(etok - 1) == ':') {
|
||||
etok[-1] = to_delim;
|
||||
etok[0] = to_delim;
|
||||
p = ++etok;
|
||||
continue; /* ignore empty bucket */
|
||||
} else if (etok = strpbrk(etok+1, ":;")) {
|
||||
/* found one to count, handle drive letter */
|
||||
*etok = to_delim;
|
||||
p = ++etok;
|
||||
} else
|
||||
/* all finished, force abort */
|
||||
p += strlen(p);
|
||||
} else {
|
||||
/* found another one, no drive letter */
|
||||
*etok = to_delim;
|
||||
p = ++etok;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* convert to backward slashes */
|
||||
for (p = Path, p = strchr(p, '/'); p; p = strchr(p, '/'))
|
||||
*p = '\\';
|
||||
#endif
|
||||
return Path;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert to forward slashes. Resolve to full pathname optionally
|
||||
*/
|
||||
char *
|
||||
w32ify(char *filename, int resolve)
|
||||
{
|
||||
static char w32_path[FILENAME_MAX];
|
||||
char *p;
|
||||
|
||||
if (resolve)
|
||||
_fullpath(w32_path, filename, sizeof (w32_path));
|
||||
else
|
||||
strncpy(w32_path, filename, sizeof (w32_path));
|
||||
|
||||
for (p = w32_path; p && *p; p++)
|
||||
if (*p == '\\')
|
||||
*p = '/';
|
||||
|
||||
return w32_path;
|
||||
}
|
||||
|
||||
char *
|
||||
getcwd_fs(char* buf, int len)
|
||||
{
|
||||
char *p;
|
||||
|
||||
if (p = getcwd(buf, len)) {
|
||||
char *q = w32ify(buf, 0);
|
||||
strncpy(buf, q, len);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
#ifdef unused
|
||||
/*
|
||||
* Convert delimiter separated pathnames (e.g. PATH) or single file pathname
|
||||
* (e.g. c:/foo, c:\bar) to NutC format. If we are handed a string that
|
||||
* _NutPathToNutc() fails to convert, just return the path we were handed
|
||||
* and assume the caller will know what to do with it (It was probably
|
||||
* a mistake to try and convert it anyway due to some of the bizarre things
|
||||
* that might look like pathnames in makefiles).
|
||||
*/
|
||||
char *
|
||||
convert_path_to_nutc(char *path)
|
||||
{
|
||||
int count; /* count of path elements */
|
||||
char *nutc_path; /* new NutC path */
|
||||
int nutc_path_len; /* length of buffer to allocate for new path */
|
||||
char *pathp; /* pointer to nutc_path used to build it */
|
||||
char *etok; /* token separator for old path */
|
||||
char *p; /* points to element of old path */
|
||||
char sep; /* what flavor of separator used in old path */
|
||||
char *rval;
|
||||
|
||||
/* is this a multi-element path ? */
|
||||
for (p = path, etok = strpbrk(p, ":;"), count = 0;
|
||||
etok;
|
||||
etok = strpbrk(p, ":;"))
|
||||
if ((etok - p) == 1) {
|
||||
if (*(etok - 1) == ';' ||
|
||||
*(etok - 1) == ':') {
|
||||
p = ++etok;
|
||||
continue; /* ignore empty bucket */
|
||||
} else if (etok = strpbrk(etok+1, ":;"))
|
||||
/* found one to count, handle drive letter */
|
||||
p = ++etok, count++;
|
||||
else
|
||||
/* all finished, force abort */
|
||||
p += strlen(p);
|
||||
} else
|
||||
/* found another one, no drive letter */
|
||||
p = ++etok, count++;
|
||||
|
||||
if (count) {
|
||||
count++; /* x1;x2;x3 <- need to count x3 */
|
||||
|
||||
/*
|
||||
* Hazard a guess on how big the buffer needs to be.
|
||||
* We have to convert things like c:/foo to /c=/foo.
|
||||
*/
|
||||
nutc_path_len = strlen(path) + (count*2) + 1;
|
||||
nutc_path = xmalloc(nutc_path_len);
|
||||
pathp = nutc_path;
|
||||
*pathp = '\0';
|
||||
|
||||
/*
|
||||
* Loop through PATH and convert one elemnt of the path at at
|
||||
* a time. Single file pathnames will fail this and fall
|
||||
* to the logic below loop.
|
||||
*/
|
||||
for (p = path, etok = strpbrk(p, ":;");
|
||||
etok;
|
||||
etok = strpbrk(p, ":;")) {
|
||||
|
||||
/* don't trip up on device specifiers or empty path slots */
|
||||
if ((etok - p) == 1)
|
||||
if (*(etok - 1) == ';' ||
|
||||
*(etok - 1) == ':') {
|
||||
p = ++etok;
|
||||
continue;
|
||||
} else if ((etok = strpbrk(etok+1, ":;")) == NULL)
|
||||
break; /* thing found was a WIN32 pathname */
|
||||
|
||||
/* save separator */
|
||||
sep = *etok;
|
||||
|
||||
/* terminate the current path element -- temporarily */
|
||||
*etok = '\0';
|
||||
|
||||
#ifdef __NUTC__
|
||||
/* convert to NutC format */
|
||||
if (_NutPathToNutc(p, pathp, 0) == FALSE) {
|
||||
free(nutc_path);
|
||||
rval = savestring(path, strlen(path));
|
||||
return rval;
|
||||
}
|
||||
#else
|
||||
*pathp++ = '/';
|
||||
*pathp++ = p[0];
|
||||
*pathp++ = '=';
|
||||
*pathp++ = '/';
|
||||
strcpy(pathp, &p[2]);
|
||||
#endif
|
||||
|
||||
pathp += strlen(pathp);
|
||||
*pathp++ = ':'; /* use Unix style path separtor for new path */
|
||||
*pathp = '\0'; /* make sure we are null terminaed */
|
||||
|
||||
/* restore path separator */
|
||||
*etok = sep;
|
||||
|
||||
/* point p to first char of next path element */
|
||||
p = ++etok;
|
||||
|
||||
}
|
||||
} else {
|
||||
nutc_path_len = strlen(path) + 3;
|
||||
nutc_path = xmalloc(nutc_path_len);
|
||||
pathp = nutc_path;
|
||||
*pathp = '\0';
|
||||
p = path;
|
||||
}
|
||||
|
||||
/*
|
||||
* OK, here we handle the last element in PATH (e.g. c of a;b;c)
|
||||
* or the path was a single filename and will be converted
|
||||
* here. Note, testing p here assures that we don't trip up
|
||||
* on paths like a;b; which have trailing delimiter followed by
|
||||
* nothing.
|
||||
*/
|
||||
if (*p != '\0') {
|
||||
#ifdef __NUTC__
|
||||
if (_NutPathToNutc(p, pathp, 0) == FALSE) {
|
||||
free(nutc_path);
|
||||
rval = savestring(path, strlen(path));
|
||||
return rval;
|
||||
}
|
||||
#else
|
||||
*pathp++ = '/';
|
||||
*pathp++ = p[0];
|
||||
*pathp++ = '=';
|
||||
*pathp++ = '/';
|
||||
strcpy(pathp, &p[2]);
|
||||
#endif
|
||||
} else
|
||||
*(pathp-1) = '\0'; /* we're already done, don't leave trailing : */
|
||||
|
||||
rval = savestring(nutc_path, strlen(nutc_path));
|
||||
free(nutc_path);
|
||||
return rval;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -1,59 +1,59 @@
|
||||
# NOTE: If you have no `make' program at all to process this makefile, run
|
||||
# `build.bat' instead.
|
||||
#
|
||||
# Copyright (C) 1988, 89, 91, 92, 93, 94, 95, 1996 Free Software Foundation, Inc
|
||||
# This file is part of GNU Make.
|
||||
#
|
||||
# GNU Make is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# GNU Make is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with GNU Make; see the file COPYING. If not, write to
|
||||
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
#
|
||||
# NMakefile for GNU Make (subproc library)
|
||||
#
|
||||
LIB = lib
|
||||
CC = cl
|
||||
|
||||
OUTDIR=.
|
||||
MAKEFILE=NMakefile
|
||||
|
||||
CFLAGS_any = /nologo /MT /W3 /GX /Z7 /YX /D WIN32 /D _WINDOWS -I. -I../include
|
||||
CFLAGS_debug = $(CFLAGS_any) /Od /D _DEBUG /FR.\WinDebug\ /Fp.\WinDebug\subproc.pch /Fo.\WinDebug/
|
||||
CFLAGS_release = $(CFLAGS_any) /O2 /FR.\WinRel\ /Fp.\WinRel\subproc.pch /Fo.\WinRel/
|
||||
|
||||
all: Release Debug
|
||||
|
||||
Release:
|
||||
$(MAKE) /f $(MAKEFILE) OUTDIR=WinRel CFLAGS="$(CFLAGS_release)" WinRel/subproc.lib
|
||||
Debug:
|
||||
$(MAKE) /f $(MAKEFILE) OUTDIR=WinDebug CFLAGS="$(CFLAGS_debug)" WinDebug/subproc.lib
|
||||
|
||||
clean:
|
||||
rmdir /s /q WinRel WinDebug
|
||||
|
||||
$(OUTDIR):
|
||||
if not exist .\$@\nul mkdir .\$@
|
||||
|
||||
OBJS = $(OUTDIR)/misc.obj $(OUTDIR)/w32err.obj $(OUTDIR)/sub_proc.obj
|
||||
|
||||
$(OUTDIR)/subproc.lib: $(OUTDIR) $(OBJS)
|
||||
$(LIB) -out:$@ @<<
|
||||
$(OBJS)
|
||||
<<
|
||||
|
||||
.c{$(OUTDIR)}.obj:
|
||||
$(CC) $(CFLAGS) /c $<
|
||||
|
||||
$(OUTDIR)/misc.obj: misc.c proc.h
|
||||
$(OUTDIR)/sub_proc.obj: sub_proc.c ../include/sub_proc.h ../include/w32err.h proc.h
|
||||
$(OUTDIR)/w32err.obj: w32err.c ../include/w32err.h
|
||||
# NOTE: If you have no `make' program at all to process this makefile, run
|
||||
# `build.bat' instead.
|
||||
#
|
||||
# Copyright (C) 1988, 89, 91, 92, 93, 94, 95, 1996 Free Software Foundation, Inc
|
||||
# This file is part of GNU Make.
|
||||
#
|
||||
# GNU Make is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# GNU Make is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with GNU Make; see the file COPYING. If not, write to
|
||||
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
#
|
||||
# NMakefile for GNU Make (subproc library)
|
||||
#
|
||||
LIB = lib
|
||||
CC = cl
|
||||
|
||||
OUTDIR=.
|
||||
MAKEFILE=NMakefile
|
||||
|
||||
CFLAGS_any = /nologo /MT /W3 /GX /Z7 /YX /D WIN32 /D _WINDOWS -I. -I../include
|
||||
CFLAGS_debug = $(CFLAGS_any) /Od /D _DEBUG /FR.\WinDebug\ /Fp.\WinDebug\subproc.pch /Fo.\WinDebug/
|
||||
CFLAGS_release = $(CFLAGS_any) /O2 /FR.\WinRel\ /Fp.\WinRel\subproc.pch /Fo.\WinRel/
|
||||
|
||||
all: Release Debug
|
||||
|
||||
Release:
|
||||
$(MAKE) /f $(MAKEFILE) OUTDIR=WinRel CFLAGS="$(CFLAGS_release)" WinRel/subproc.lib
|
||||
Debug:
|
||||
$(MAKE) /f $(MAKEFILE) OUTDIR=WinDebug CFLAGS="$(CFLAGS_debug)" WinDebug/subproc.lib
|
||||
|
||||
clean:
|
||||
rmdir /s /q WinRel WinDebug
|
||||
|
||||
$(OUTDIR):
|
||||
if not exist .\$@\nul mkdir .\$@
|
||||
|
||||
OBJS = $(OUTDIR)/misc.obj $(OUTDIR)/w32err.obj $(OUTDIR)/sub_proc.obj
|
||||
|
||||
$(OUTDIR)/subproc.lib: $(OUTDIR) $(OBJS)
|
||||
$(LIB) -out:$@ @<<
|
||||
$(OBJS)
|
||||
<<
|
||||
|
||||
.c{$(OUTDIR)}.obj:
|
||||
$(CC) $(CFLAGS) /c $<
|
||||
|
||||
$(OUTDIR)/misc.obj: misc.c proc.h
|
||||
$(OUTDIR)/sub_proc.obj: sub_proc.c ../include/sub_proc.h ../include/w32err.h proc.h
|
||||
$(OUTDIR)/w32err.obj: w32err.c ../include/w32err.h
|
||||
|
@ -1,10 +1,10 @@
|
||||
if not exist .\WinDebug\nul mkdir .\WinDebug
|
||||
cl.exe /nologo /MT /W3 /GX /Z7 /YX /Od /I .. /I . /I ../include /D WIN32 /D _DEBUG /D _WINDOWS /FR.\WinDebug/ /Fp.\WinDebug/subproc.pch /Fo.\WinDebug/ /c misc.c
|
||||
cl.exe /nologo /MT /W3 /GX /Z7 /YX /Od /I .. /I . /I ../include /D WIN32 /D _DEBUG /D _WINDOWS /FR.\WinDebug/ /Fp.\WinDebug/subproc.pch /Fo.\WinDebug/ /c sub_proc.c
|
||||
cl.exe /nologo /MT /W3 /GX /Z7 /YX /Od /I .. /I . /I ../include /D WIN32 /D _DEBUG /D _WINDOWS /FR.\WinDebug/ /Fp.\WinDebug/subproc.pch /Fo.\WinDebug/ /c w32err.c
|
||||
lib.exe /NOLOGO /OUT:.\WinDebug\subproc.lib .\WinDebug/misc.obj .\WinDebug/sub_proc.obj .\WinDebug/w32err.obj
|
||||
if not exist .\WinRel\nul mkdir .\WinRel
|
||||
cl.exe /nologo /MT /W3 /GX /YX /O2 /I ../include /D WIN32 /D NDEBUG /D _WINDOWS /FR.\WinRel/ /Fp.\WinRel/subproc.pch /Fo.\WinRel/ /c misc.c
|
||||
cl.exe /nologo /MT /W3 /GX /YX /O2 /I ../include /D WIN32 /D NDEBUG /D _WINDOWS /FR.\WinRel/ /Fp.\WinRel/subproc.pch /Fo.\WinRel/ /c sub_proc.c
|
||||
cl.exe /nologo /MT /W3 /GX /YX /O2 /I ../include /D WIN32 /D NDEBUG /D _WINDOWS /FR.\WinRel/ /Fp.\WinRel/subproc.pch /Fo.\WinRel/ /c w32err.c
|
||||
lib.exe /NOLOGO /OUT:.\WinRel\subproc.lib .\WinRel/misc.obj .\WinRel/sub_proc.obj .\WinRel/w32err.obj
|
||||
if not exist .\WinDebug\nul mkdir .\WinDebug
|
||||
cl.exe /nologo /MT /W3 /GX /Z7 /YX /Od /I .. /I . /I ../include /D WIN32 /D _DEBUG /D _WINDOWS /FR.\WinDebug/ /Fp.\WinDebug/subproc.pch /Fo.\WinDebug/ /c misc.c
|
||||
cl.exe /nologo /MT /W3 /GX /Z7 /YX /Od /I .. /I . /I ../include /D WIN32 /D _DEBUG /D _WINDOWS /FR.\WinDebug/ /Fp.\WinDebug/subproc.pch /Fo.\WinDebug/ /c sub_proc.c
|
||||
cl.exe /nologo /MT /W3 /GX /Z7 /YX /Od /I .. /I . /I ../include /D WIN32 /D _DEBUG /D _WINDOWS /FR.\WinDebug/ /Fp.\WinDebug/subproc.pch /Fo.\WinDebug/ /c w32err.c
|
||||
lib.exe /NOLOGO /OUT:.\WinDebug\subproc.lib .\WinDebug/misc.obj .\WinDebug/sub_proc.obj .\WinDebug/w32err.obj
|
||||
if not exist .\WinRel\nul mkdir .\WinRel
|
||||
cl.exe /nologo /MT /W3 /GX /YX /O2 /I ../include /D WIN32 /D NDEBUG /D _WINDOWS /FR.\WinRel/ /Fp.\WinRel/subproc.pch /Fo.\WinRel/ /c misc.c
|
||||
cl.exe /nologo /MT /W3 /GX /YX /O2 /I ../include /D WIN32 /D NDEBUG /D _WINDOWS /FR.\WinRel/ /Fp.\WinRel/subproc.pch /Fo.\WinRel/ /c sub_proc.c
|
||||
cl.exe /nologo /MT /W3 /GX /YX /O2 /I ../include /D WIN32 /D NDEBUG /D _WINDOWS /FR.\WinRel/ /Fp.\WinRel/subproc.pch /Fo.\WinRel/ /c w32err.c
|
||||
lib.exe /NOLOGO /OUT:.\WinRel\subproc.lib .\WinRel/misc.obj .\WinRel/sub_proc.obj .\WinRel/w32err.obj
|
||||
|
@ -1,63 +1,63 @@
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <windows.h>
|
||||
#include "proc.h"
|
||||
|
||||
|
||||
/*
|
||||
* Description: Convert a NULL string terminated UNIX environment block to
|
||||
* an environment block suitable for a win32 system call
|
||||
*
|
||||
* Returns: TRUE= success, FALSE=fail
|
||||
*
|
||||
* Notes/Dependencies: the environment block is sorted in case-insensitive
|
||||
* order, is double-null terminated, and is a char *, not a char **
|
||||
*/
|
||||
int _cdecl compare(const void *a1, const void *a2)
|
||||
{
|
||||
return _stricoll(*((char**)a1),*((char**)a2));
|
||||
}
|
||||
bool_t
|
||||
arr2envblk(char **arr, char **envblk_out)
|
||||
{
|
||||
char **tmp;
|
||||
int size_needed;
|
||||
int arrcnt;
|
||||
char *ptr;
|
||||
|
||||
arrcnt = 0;
|
||||
while (arr[arrcnt]) {
|
||||
arrcnt++;
|
||||
}
|
||||
|
||||
tmp = (char**) calloc(arrcnt + 1, sizeof(char *));
|
||||
if (!tmp) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
arrcnt = 0;
|
||||
size_needed = 0;
|
||||
while (arr[arrcnt]) {
|
||||
tmp[arrcnt] = arr[arrcnt];
|
||||
size_needed += strlen(arr[arrcnt]) + 1;
|
||||
arrcnt++;
|
||||
}
|
||||
size_needed++;
|
||||
|
||||
qsort((void *) tmp, (size_t) arrcnt, sizeof (char*), compare);
|
||||
|
||||
ptr = *envblk_out = calloc(size_needed, 1);
|
||||
if (!ptr) {
|
||||
free(tmp);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
arrcnt = 0;
|
||||
while (tmp[arrcnt]) {
|
||||
strcpy(ptr, tmp[arrcnt]);
|
||||
ptr += strlen(tmp[arrcnt]) + 1;
|
||||
arrcnt++;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <windows.h>
|
||||
#include "proc.h"
|
||||
|
||||
|
||||
/*
|
||||
* Description: Convert a NULL string terminated UNIX environment block to
|
||||
* an environment block suitable for a win32 system call
|
||||
*
|
||||
* Returns: TRUE= success, FALSE=fail
|
||||
*
|
||||
* Notes/Dependencies: the environment block is sorted in case-insensitive
|
||||
* order, is double-null terminated, and is a char *, not a char **
|
||||
*/
|
||||
int _cdecl compare(const void *a1, const void *a2)
|
||||
{
|
||||
return _stricoll(*((char**)a1),*((char**)a2));
|
||||
}
|
||||
bool_t
|
||||
arr2envblk(char **arr, char **envblk_out)
|
||||
{
|
||||
char **tmp;
|
||||
int size_needed;
|
||||
int arrcnt;
|
||||
char *ptr;
|
||||
|
||||
arrcnt = 0;
|
||||
while (arr[arrcnt]) {
|
||||
arrcnt++;
|
||||
}
|
||||
|
||||
tmp = (char**) calloc(arrcnt + 1, sizeof(char *));
|
||||
if (!tmp) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
arrcnt = 0;
|
||||
size_needed = 0;
|
||||
while (arr[arrcnt]) {
|
||||
tmp[arrcnt] = arr[arrcnt];
|
||||
size_needed += strlen(arr[arrcnt]) + 1;
|
||||
arrcnt++;
|
||||
}
|
||||
size_needed++;
|
||||
|
||||
qsort((void *) tmp, (size_t) arrcnt, sizeof (char*), compare);
|
||||
|
||||
ptr = *envblk_out = calloc(size_needed, 1);
|
||||
if (!ptr) {
|
||||
free(tmp);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
arrcnt = 0;
|
||||
while (tmp[arrcnt]) {
|
||||
strcpy(ptr, tmp[arrcnt]);
|
||||
ptr += strlen(tmp[arrcnt]) + 1;
|
||||
arrcnt++;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
#ifndef _PROC_H
|
||||
#define _PROC_H
|
||||
|
||||
typedef int bool_t;
|
||||
|
||||
#define E_SCALL 101
|
||||
#define E_IO 102
|
||||
#define E_NO_MEM 103
|
||||
#define E_FORK 104
|
||||
|
||||
extern bool_t arr2envblk(char **arr, char **envblk_out);
|
||||
|
||||
#endif
|
||||
#ifndef _PROC_H
|
||||
#define _PROC_H
|
||||
|
||||
typedef int bool_t;
|
||||
|
||||
#define E_SCALL 101
|
||||
#define E_IO 102
|
||||
#define E_NO_MEM 103
|
||||
#define E_FORK 104
|
||||
|
||||
extern bool_t arr2envblk(char **arr, char **envblk_out);
|
||||
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,51 +1,51 @@
|
||||
#include <windows.h>
|
||||
#include "w32err.h"
|
||||
|
||||
/*
|
||||
* Description: the win32 version of perror()
|
||||
*
|
||||
* Returns: a pointer to a static error
|
||||
*
|
||||
* Notes/Dependencies: I got this from
|
||||
* comp.os.ms-windows.programmer.win32
|
||||
*/
|
||||
char *
|
||||
map_win32_error_to_string (DWORD ercode) {
|
||||
/* __declspec (thread) necessary if you will use multiple threads */
|
||||
__declspec (thread) static char szMessageBuffer[128];
|
||||
|
||||
/* Fill message buffer with a default message in
|
||||
* case FormatMessage fails
|
||||
*/
|
||||
wsprintf (szMessageBuffer, "Error %ld", ercode);
|
||||
|
||||
/*
|
||||
* Special code for winsock error handling.
|
||||
*/
|
||||
if (ercode > WSABASEERR) {
|
||||
HMODULE hModule = GetModuleHandle("wsock32");
|
||||
if (hModule != NULL) {
|
||||
FormatMessage(FORMAT_MESSAGE_FROM_HMODULE,
|
||||
hModule,
|
||||
ercode,
|
||||
LANG_NEUTRAL,
|
||||
szMessageBuffer,
|
||||
sizeof(szMessageBuffer),
|
||||
NULL);
|
||||
FreeLibrary(hModule);
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* Default system message handling
|
||||
*/
|
||||
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
|
||||
NULL,
|
||||
ercode,
|
||||
LANG_NEUTRAL,
|
||||
szMessageBuffer,
|
||||
sizeof(szMessageBuffer),
|
||||
NULL);
|
||||
}
|
||||
return szMessageBuffer;
|
||||
}
|
||||
|
||||
#include <windows.h>
|
||||
#include "w32err.h"
|
||||
|
||||
/*
|
||||
* Description: the win32 version of perror()
|
||||
*
|
||||
* Returns: a pointer to a static error
|
||||
*
|
||||
* Notes/Dependencies: I got this from
|
||||
* comp.os.ms-windows.programmer.win32
|
||||
*/
|
||||
char *
|
||||
map_win32_error_to_string (DWORD ercode) {
|
||||
/* __declspec (thread) necessary if you will use multiple threads */
|
||||
__declspec (thread) static char szMessageBuffer[128];
|
||||
|
||||
/* Fill message buffer with a default message in
|
||||
* case FormatMessage fails
|
||||
*/
|
||||
wsprintf (szMessageBuffer, "Error %ld", ercode);
|
||||
|
||||
/*
|
||||
* Special code for winsock error handling.
|
||||
*/
|
||||
if (ercode > WSABASEERR) {
|
||||
HMODULE hModule = GetModuleHandle("wsock32");
|
||||
if (hModule != NULL) {
|
||||
FormatMessage(FORMAT_MESSAGE_FROM_HMODULE,
|
||||
hModule,
|
||||
ercode,
|
||||
LANG_NEUTRAL,
|
||||
szMessageBuffer,
|
||||
sizeof(szMessageBuffer),
|
||||
NULL);
|
||||
FreeLibrary(hModule);
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* Default system message handling
|
||||
*/
|
||||
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
|
||||
NULL,
|
||||
ercode,
|
||||
LANG_NEUTRAL,
|
||||
szMessageBuffer,
|
||||
sizeof(szMessageBuffer),
|
||||
NULL);
|
||||
}
|
||||
return szMessageBuffer;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user