Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 4972 → Rev 4973

/programs/develop/libraries/menuetlibc/src/libc/dos/Makefile
0,0 → 1,29
all:
make -C compat
make -C dir
make -C dos
make -C dos_emu
make -C errno
make -C io
make -C process
make -C sys
 
clean:
make -C compat clean
make -C dir clean
make -C dos clean
make -C dos_emu clean
make -C errno clean
make -C io clean
make -C process clean
make -C sys clean
 
depend:
make -C compat depend
make -C dir depend
make -C dos depend
make -C dos_emu depend
make -C errno depend
make -C io depend
make -C process depend
make -C sys depend
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/Makefile
0,0 → 1,6
THIS_SRCS = d_close.c d_commit.c d_creat.c d_creatn.c d_exterr.c d_findf.c \
d_findn.c d_getdat.c d_getdf.c d_getdrv.c d_getfa.c d_getftm.c \
d_gettim.c d_open.c d_read.c d_setdat.c d_setdrv.c d_setfa.c d_setftm.c \
d_settim.c d_write.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_close.c
0,0 → 1,19
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_CLOSE.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <libc/dosio.h>
#include <errno.h>
#include <dos.h>
 
unsigned int _dos_close(int handle)
{
return dosemu_close(handle);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_commit.c
0,0 → 1,20
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_COMMIT.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <libc/dosio.h>
#include <errno.h>
#include <dos.h>
 
unsigned int _dos_commit(int handle)
{
_dosemu_flush(handle);
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_creat.c
0,0 → 1,27
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_CREAT.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <libc/dosio.h>
#include <errno.h>
#include <dos.h>
#include <unistd.h>
#include <fcntl.h>
 
static char buf[1];
 
unsigned int _dos_creat(const char *filename, unsigned int attr, int *handle)
{
int i;
i=dosemu_open(filename,attr|O_CREAT);
if(i==-1) return -1;
if(handle) *handle=i;
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_creatn.c
0,0 → 1,27
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_CREATN.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <libc/dosio.h>
#include <errno.h>
#include <dos.h>
#include<unistd.h>
#include <fcntl.h>
 
static char buf[1];
 
unsigned int _dos_creatnew(const char *filename, unsigned int attr, int *handle)
{
int i;
i=dosemu_open(filename,attr|O_CREAT|O_EXCL);
if(i==-1) return -1;
if(handle) *handle=i;
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_exterr.c
0,0 → 1,17
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_EXTERR.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <dos.h>
 
int _dosexterr(struct _DOSERROR *p_error)
{
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_findf.c
0,0 → 1,21
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_FINDF.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <libc/stubs.h>
#include <libc/dosio.h>
#include <errno.h>
#include <string.h>
#include <dos.h>
 
unsigned int _dos_findfirst(char *name, unsigned int attr, struct _find_t *result)
{
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_findn.c
0,0 → 1,20
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_FINDN.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <libc/stubs.h>
#include <libc/dosio.h>
#include <errno.h>
#include <dos.h>
 
unsigned int _dos_findnext(struct _find_t *result)
{
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_getdat.c
0,0 → 1,17
#include <errno.h>
#include <dos.h>
 
#define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10)
 
void _dos_getdate(struct _dosdate_t *date)
{
unsigned long tmp;
__asm__ __volatile__("int $0x40":"=a"(tmp):"0"(29));
date->year=2000+(tmp&0xff);
date->month=(tmp>>8)&0xff;
date->day= (tmp>>16)&0xff;
date->dayofweek=0; /* xxx - how to do it correctly ? */
BCD_TO_BIN(date->year);
BCD_TO_BIN(date->month);
BCD_TO_BIN(date->day);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_getdf.c
0,0 → 1,22
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_GETDF.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <dos.h>
#include <errno.h>
 
unsigned int _dos_getdiskfree(unsigned int drive, struct _diskfree_t *diskspace)
{
diskspace->sectors_per_cluster = 1;
diskspace->avail_clusters = 0xFFFF;
diskspace->bytes_per_sector = 512;
diskspace->total_clusters = 0xFFFF;
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_getdrv.c
0,0 → 1,17
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_GETDRV.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <dos.h>
 
void _dos_getdrive(unsigned int *p_drive)
{
*p_drive = 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_getfa.c
0,0 → 1,19
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_GETFA.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <libc/dosio.h>
#include <errno.h>
#include <dos.h>
 
unsigned int _dos_getfileattr(const char *filename, unsigned int *p_attr)
{
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_getftm.c
0,0 → 1,18
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_GETFTM.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <errno.h>
#include <dos.h>
 
unsigned int _dos_getftime(int handle, unsigned int *p_date, unsigned int *p_time)
{
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_gettim.c
0,0 → 1,15
#define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10)
 
#include <dos.h>
 
void _dos_gettime(struct _dostime_t *time)
{
unsigned long tmp=__menuet__getsystemclock();
time->hour=tmp&0xff;
time->minute=(tmp>>8)&0xff;
time->second=(tmp>>16)&0xff;
time->hsecond=0;
BCD_TO_BIN(time->hour);
BCD_TO_BIN(time->minute);
BCD_TO_BIN(time->second);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_open.c
0,0 → 1,24
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_OPEN.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <libc/dosio.h>
#include <errno.h>
#include <dos.h>
#include<menuet/os.h>
 
unsigned int _dos_open(const char *filename, unsigned int mode, int *handle)
{
int i;
i=dosemu_open(filename,mode);
if(i==-1) return -1;
if(handle) *handle=i;
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_read.c
0,0 → 1,27
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_READ.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <libc/stubs.h>
#include <libc/dosio.h>
#include <errno.h>
#include <dos.h>
#define FSLAYER
#include<menuet/os.h>
 
unsigned int _dos_read(int handle, void *buffer, unsigned int count, unsigned int *result)
{
int p;
p=dosemu_read(handle,buffer,count);
if(p==-1) return p;
if(result) *result=p;
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_setdat.c
0,0 → 1,17
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_SETDAT.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <errno.h>
#include <dos.h>
 
unsigned int _dos_setdate(struct _dosdate_t *date)
{
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_setdrv.c
0,0 → 1,16
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_SETDRV.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <dos.h>
 
void _dos_setdrive(unsigned int drive, unsigned int *p_drives)
{
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_setfa.c
0,0 → 1,18
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_SETFA.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <libc/dosio.h>
#include <errno.h>
#include <dos.h>
 
unsigned int _dos_setfileattr(const char *filename, unsigned int attr)
{
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_setftm.c
0,0 → 1,18
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_SETFTM.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <errno.h>
#include <dos.h>
 
unsigned int _dos_setftime(int handle, unsigned int date, unsigned int time)
{
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_settim.c
0,0 → 1,18
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_SETTIM.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <errno.h>
#include <dos.h>
 
unsigned int _dos_settime(struct _dostime_t *time)
{
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/compat/d_write.c
0,0 → 1,25
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* D_WITE.C.
*
* Written by Peter Sulyok 1995 <sulyok@math.klte.hu>.
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
 
#include <libc/stubs.h>
#include <libc/dosio.h>
#include <errno.h>
#include <dos.h>
 
unsigned int _dos_write(int handle, const void *buffer, unsigned int count, unsigned int *result)
{
int p;
p=dosemu_write(handle,buffer,count);
if(p==-1) return p;
if(result) *result=p;
return 0;
}
 
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/Makefile
0,0 → 1,4
THIS_SRCS = findfirs.c findnext.c fnmerge.c fnsplit.c ftreewlk.c \
ftw.c getdisk.c setdisk.c srchpath.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/findfirs.c
0,0 → 1,12
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <dir.h>
#include <libc/dosio.h>
 
int findfirst(const char *pathname, struct ffblk *ffblk, int attrib)
{
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/findnext.c
0,0 → 1,12
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <dir.h>
#include <libc/dosio.h>
 
int findnext(struct ffblk *ffblk)
{
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/fnmerge.c
0,0 → 1,32
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dir.h>
#include <string.h>
 
void
fnmerge (char *path, const char *drive, const char *dir,
const char *name, const char *ext)
{
*path = '\0';
if (drive && *drive)
{
path[0] = drive[0];
path[1] = ':';
path[2] = 0;
}
if (dir && *dir)
{
char last_dir_char = dir[strlen(dir) - 1];
 
strcat(path, dir);
if (last_dir_char != '/' && last_dir_char != '\\')
strcat(path, strchr(dir, '\\') ? "\\" : "/");
}
if (name)
strcat(path, name);
if (ext && *ext)
{
if (*ext != '.')
strcat(path, ".");
strcat(path, ext);
}
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/fnsplit.c
0,0 → 1,120
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dir.h>
#include <ctype.h>
#include <string.h>
 
static char *
max_ptr(char *p1, char *p2)
{
if (p1 > p2)
return p1;
else
return p2;
}
 
int
fnsplit (const char *path, char *drive, char *dir,
char *name, char *ext)
{
int flags = 0, len;
const char *pp, *pe;
 
if (drive)
*drive = '\0';
if (dir)
*dir = '\0';
if (name)
*name = '\0';
if (ext)
*ext = '\0';
 
pp = path;
 
if ((isalpha(*pp) || strchr("[\\]^_`", *pp)) && (pp[1] == ':'))
{
flags |= DRIVE;
if (drive)
{
strncpy(drive, pp, 2);
drive[2] = '\0';
}
pp += 2;
}
 
pe = max_ptr(strrchr(pp, '\\'), strrchr(pp, '/'));
if (pe)
{
flags |= DIRECTORY;
pe++;
len = pe - pp;
if (dir)
{
strncpy(dir, pp, len);
dir[len] = '\0';
}
pp = pe;
}
else
pe = pp;
 
/* Special case: "c:/path/." or "c:/path/.."
These mean FILENAME, not EXTENSION. */
while (*pp == '.')
++pp;
if (pp > pe)
{
flags |= FILENAME;
if (name)
{
len = pp - pe;
strncpy(name, pe, len);
name[len] = '\0';
}
}
 
pe = strrchr(pp, '.');
if (pe)
{
flags |= EXTENSION;
if (ext)
strcpy(ext, pe);
}
else
pe = strchr( pp, '\0');
 
if (pp != pe)
{
flags |= FILENAME;
len = pe - pp;
if (name)
{
strncpy(name, pp, len);
name[len] = '\0';
}
}
 
if (strcspn(path, "*?[") < strlen(path))
flags |= WILDCARDS;
 
return flags;
}
 
#ifdef TEST
 
#include <stdio.h>
 
int
main(void)
{
char arg[81], drive[81], dir[81], fname[81], ext[81];
 
fputs("> ", stdout); fflush(stdout);
gets(arg);
 
printf("`%s' (%x): `%s' `%s' `%s' `%s'\n", arg,
fnsplit(arg, drive, dir, fname, ext), drive, dir, fname, ext);
 
return 0;
}
 
#endif
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/ftreewlk.c
0,0 → 1,171
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* Recursively descent the directory hierarchy rooted in DIR,
* calling FUNC for each object in the hierarchy. We cannot
* use ftw(), because it uses some non-ANSI functions which
* will pollute ANSI namespace, while we need this function
* in some ANSI functions (e.g., rename()). Thus, this function
* is closely modeled on ftw(), but uses DOS directory search
* functions and structures instead of opendir()/readdir()/stat().
*
* Copyright (c) 1995 Eli Zaretskii <eliz@is.elta.co.il>
*
* This software may be used freely as long as this copyright notice is
* left intact. There is no warranty on this software.
*
*/
 
#include <libc/stubs.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <dir.h>
 
#define FA_ALL (FA_RDONLY|FA_HIDDEN|FA_SYSTEM|FA_LABEL|FA_DIREC|FA_ARCH)
 
int
__file_tree_walk(const char *dir,
int (*func)(const char *, const struct ffblk *))
{
struct ffblk ff;
unsigned char searchspec[FILENAME_MAX];
unsigned char found[FILENAME_MAX], *dir_end;
int e = errno;
 
if (dir == 0 || func == 0)
{
errno = EFAULT;
return -1;
}
 
if (*dir == '\0')
{
errno = ENOENT;
return -1;
}
 
/* Construct the search spec for findfirst(). Treat ``d:'' as ``d:.''. */
strcpy(searchspec, dir);
dir_end = searchspec + strlen(searchspec) - 1;
if (*dir_end == ':')
{
*++dir_end = '.';
*++dir_end = '\0';
}
else if (*dir_end == '/' || *dir_end == '\\')
*dir_end = '\0';
else
++dir_end;
strcpy(dir_end, "/*.*");
 
/* Prepare the buffer where the full pathname of the found files
will be placed. */
strcpy(found, dir);
dir_end = found + strlen(found) - 1;
if (*dir_end == ':')
{
*++dir_end = '.';
dir_end[1] = '\0';
}
if (*dir_end != '/' && *dir_end != '\\')
{
/* Try to preserve user's forward/backward slash style. */
*++dir_end = strchr(found, '\\') == 0 ? '/': '\\';
*++dir_end = '\0';
}
else
++dir_end;
 
if (findfirst(searchspec, &ff, FA_ALL))
return -1;
 
do
{
int func_result;
unsigned char *p = dir_end;
 
/* Skip `.' and `..' entries. */
if (ff.ff_name[0] == '.' &&
(ff.ff_name[1] == '\0' || ff.ff_name[1] == '.'))
continue;
 
/* Construct full pathname in FOUND[]. */
strcpy(dir_end, ff.ff_name);
 
/* Convert name of found file to lower-case. Cannot use
strlwr() because it's non-ANSI. Sigh... */
while (*p)
*p++ = tolower(*p);
 
/* Invoke FUNC() on this file. */
if ((func_result = (*func)(found, &ff)) != 0)
return func_result;
 
/* If this is a directory, walk its siblings. */
if (ff.ff_attrib & 0x10)
{
int subwalk_result;
 
if ((subwalk_result = __file_tree_walk(found, func)) != 0)
return subwalk_result;
}
} while (findnext(&ff) == 0);
 
if (errno == ENMFILE) /* normal case: tree exhausted */
{
errno = e; /* restore errno from previous syscall */
return 0;
}
 
return -1; /* error; errno set by findnext() */
}
 
#ifdef TEST
 
#include <stdlib.h>
 
int
ff_walker(const char *path, const struct ffblk *ff)
{
printf("%s:\t%lu\t", path, ff->ff_fsize);
if (ff->ff_attrib & 1)
printf("R");
if (ff->ff_attrib & 2)
printf("H");
if (ff->ff_attrib & 4)
printf("S");
if (ff->ff_attrib & 8)
printf("V");
if (ff->ff_attrib & 0x10)
printf("D");
if (ff->ff_attrib & 0x20)
printf("A");
printf("\n");
 
if (strcmp(ff->ff_name, "XXXXX") == 0)
return 8;
return 0;
}
 
int
main(int argc, char *argv[])
{
if (argc > 1)
{
char msg[80];
 
sprintf(msg, "file_tree_walk: %d",
file_tree_walk(argv[1], ff_walker));
if (errno)
perror(msg);
else
puts(msg);
}
else
printf("Usage: %s dir\n", argv[0]);
 
return 0;
}
 
#endif
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/ftw.c
0,0 → 1,220
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/* ftw() for DJGPP.
*
* Recursively descent the directory hierarchy rooted in DIR,
* calling FUNC for each object in the hierarchy.
*
* Copyright (c) 1995 Eli Zaretskii <eliz@is.elta.co.il>
*
* This software may be used freely as long as this copyright notice is
* left intact. There is no warranty on this software.
*
*/
 
#include <libc/stubs.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <sys/stat.h>
#include <dirent.h>
#include <io.h>
#include <ftw.h>
 
static int
walk_dir(char *path, int (*func)(const char *, struct stat *, int))
{
DIR *dp;
struct dirent *de;
struct stat stbuf;
int flag;
int e = errno;
int pathlen = strlen(path);
 
if ((dp = opendir(path)) == 0)
return -1;
 
for (errno = 0; (de = readdir(dp)) != 0; errno = 0)
{
int func_result;
char lastc = de->d_name[de->d_namlen - 1];
 
/* Skip `.' and `..' entries. Checking the last char is enough,
because readdir will never return a filename which ends with
a dot. */
if (lastc == '.')
continue;
 
/* Append found name to directory path. */
if (pathlen + de->d_namlen + 1 > FILENAME_MAX)
{
(void)closedir(dp);
errno = ENAMETOOLONG;
return -1;
}
if (path[pathlen-1] == '/' || path[pathlen-1] == '\\')
pathlen--;
path[pathlen] = '/';
strcpy(path + pathlen + 1, de->d_name);
 
if (stat(path, &stbuf) < 0)
flag = FTW_NS;
else if (S_ISDIR(stbuf.st_mode))
flag = FTW_D;
else if (S_ISLABEL(stbuf.st_mode))
flag = FTW_VL;
else
flag = FTW_F;
 
/* Invoke FUNC() on this object. */
errno = e;
if ((func_result = (*func)(path, &stbuf, flag)) != 0)
{
(void)closedir(dp);
return func_result;
}
 
/* If this is a directory, walk its siblings. */
if (flag == FTW_D)
{
int subwalk_result;
 
errno = e;
if ((subwalk_result = walk_dir(path, func)) != 0)
{
(void)closedir(dp);
return subwalk_result;
}
}
 
/* Erase D_NAME[] from PATH. */
path[pathlen] = '\0';
}
 
(void)closedir(dp);
if (errno == 0) /* normal case: this subtree exhausted */
{
errno = e;/* restore errno from previous syscall */
return 0;
}
else
return -1; /* with whatever errno was set by readdir() */
}
 
int
ftw(const char *dir, int (*func)(const char *, struct stat *, int),
int ignored)
{
int flag;
unsigned char pathbuf[FILENAME_MAX];
int dirattr;
int len;
int e = errno;
 
ignored = ignored; /* pacify -Wall */
 
if (dir == 0 || func == 0)
{
errno = EFAULT;
return -1;
}
 
if (*dir == '\0')
{
errno = ENOENT;
return -1;
}
 
strcpy(pathbuf, dir);
len = strlen(pathbuf);
if (pathbuf[len-1] == ':')
{
pathbuf[len++] = '.';
pathbuf[len] = '\0';
}
 
/* Fail for non-directories. */
errno = 0;
dirattr = _chmod(pathbuf, 0, 0);
if (errno == ENOENT)
return -1;
else if ((dirattr & 0x10) != 0x10)
{
errno = ENOTDIR;
return -1;
}
else
{
int func_result;
struct stat stbuf;
 
if (stat(pathbuf, &stbuf) < 0)
flag = FTW_NS;
else
flag = FTW_D;
errno = e;
if ((func_result = (*func)(pathbuf, &stbuf, flag)) != 0)
return func_result;
return walk_dir(pathbuf, func);
}
}
 
#ifdef TEST
 
#include <stdlib.h>
 
int
ftw_walker(const char *path, struct stat *sb, int flag)
{
char *base;
 
printf("%s:\t%u\t", path, sb->st_size);
if (S_ISLABEL(sb->st_mode))
printf("V");
if (S_ISDIR(sb->st_mode))
printf("D");
if (S_ISCHR(sb->st_mode))
printf("C");
if (sb->st_mode & S_IRUSR)
printf("r");
if (sb->st_mode & S_IWUSR)
printf("w");
if (sb->st_mode & S_IXUSR)
printf("x");
 
if (flag == FTW_NS)
printf(" !!no_stat!!");
printf("\n");
 
base = strrchr(path, '/');
if (base == 0)
base = strrchr(path, '\\');
if (base == 0)
base = strrchr(path, ':');
if (strcmp(base == 0 ? path : base + 1, "xxxxx") == 0)
return 8;
return 0;
}
 
int
main(int argc, char *argv[])
{
if (argc > 1)
{
char msg[80];
 
sprintf(msg, "file_tree_walk: %d",
ftw(argv[1], ftw_walker, 0));
if (errno)
perror(msg);
else
puts(msg);
}
else
printf("Usage: %s dir\n", argv[0]);
 
return 0;
}
 
#endif
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/getdisk.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <dir.h>
 
int getdisk(void)
{
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/setdisk.c
0,0 → 1,7
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dir.h>
 
int setdisk(int _drive)
{
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dir/srchpath.c
0,0 → 1,92
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <limits.h>
#include <dir.h>
/* Search PATH for FILE.
If successful, store the full pathname in static buffer and return a
pointer to it.
If not sucessful, return NULL.
This is what the Borland searchpath() library function does.
*/
char *
searchpath(const char *file)
{
static char found[PATH_MAX];
static char *path;
 
memset(found, 0, sizeof(found));
/* Get the PATH and store it for reuse. */
if (path == 0)
{
char *p = getenv("PATH");
path = (char *)calloc(p ? strlen(p) + 3 : 2, sizeof(char));
if (path == (char *)0)
return (char *)0;
/* Prepend `.' to the PATH, so current directory
is always searched. */
path[0] = '.';
if (p)
{
register char *s;
path[1] = ';';
strcpy(path+2, p);
/* Convert to more plausible form. */
for (s = path; *s; ++s)
{
if (*s == '\\')
*s = '/';
if (isupper(*s))
*s = tolower(*s);
}
}
else
path[1] = 0;
}
if (strpbrk (file, "/\\:") != 0)
{
strcpy(found, file);
return found;
}
else
{
char *test_dir = path;
do {
char *dp;
dp = strchr(test_dir, ';');
if (dp == (char *)0)
dp = test_dir + strlen(test_dir);
if (dp == test_dir)
strcpy(found, file);
else
{
strncpy(found, test_dir, dp - test_dir);
found[dp - test_dir] = '/';
strcpy(found + (dp - test_dir) + 1, file);
}
 
if (__file_exists(found))
return found;
 
if (*dp == 0)
break;
test_dir = dp + 1;
} while (*test_dir != 0);
}
return NULL;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/Makefile
0,0 → 1,6
THIS_SRCS = bdos.c bdosptr.s delay.c fexistp.c getcbrk.c getdate.c getdfree.c \
getdinfo.c getdos_v.c getftime.c gettime.c gettimeo.c \
osflavor.c osmajor.c osminor.c remotdrv.c \
remothdl.c setcbrk.c setdate.c setftime.c settime.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/bdos.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
#include <assert.h>
 
int bdos(int func, unsigned dx, unsigned al)
{
unimpl();
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/bdosptr.s
0,0 → 1,5
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
MK_C_SYM(bdosptr)
jmp C_SYM(bdos)
 
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/delay.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
#include <menuet/os.h>
 
void delay(unsigned msec)
{
__menuet__delay100(msec);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/fexistp.c
0,0 → 1,14
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
#include <errno.h>
#include <io.h>
#include <stdio.h>
 
int __file_exists(const char *fn)
{
FILE * f;
f=fopen(fn,"r");
if(!f) return 0;
fclose(f);
return 1;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/getcbrk.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
#include <assert.h>
 
int getcbrk(void)
{
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/getdate.c
0,0 → 1,17
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
#include <assert.h>
 
#define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10)
 
void getdate( struct date *dateblk)
{
unsigned long tmp;
__asm__ __volatile__("int $0x40":"=a"(tmp):"0"(29));
dateblk->da_year=2000+(tmp&0xff);
dateblk->da_mon=(tmp>>8)&0xff;
dateblk->da_day=(tmp>>16)&0xff;
BCD_TO_BIN(dateblk->da_year);
BCD_TO_BIN(dateblk->da_mon);
BCD_TO_BIN(dateblk->da_day);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/getdfree.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
#include <errno.h>
#include <assert.h>
 
void getdfree(unsigned char drive, struct dfree *dtable)
{
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/getdinfo.c
0,0 → 1,21
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/* This is file GETDINFO.C */
/*
* Get device info word by calling IOCTL Function 0.
*
* Copyright (c) 1994 Eli Zaretskii <eliz@is.elta.co.il>
*
* This software may be used freely so long as this copyright notice is
* left intact. There is no warranty on this software.
*
*/
 
#include <errno.h>
#include <libc/dosio.h>
#include <assert.h>
 
short _get_dev_info(int);
 
short _get_dev_info(int fhandle)
{
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/getdos_v.c
0,0 → 1,62
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* This is file GETDOS_V.C
*
* Copyright (c) 1994,95 Eli Zaretskii <eliz@is.elta.co.il>
*
* This software may be used freely so long as this copyright notice is
* left intact. There is no warranty on this software.
*
*/
 
#include <libc/bss.h>
#include <dos.h>
 
/* Return OS version number, either true or ``simulated'' one.
Global variables _OSMAJOR and _OSMINOR are ALWAYS set to whatever
INT 21h/AX=30h returns. Global _OS_FLAVOR is set to a string
which identifies the OEM of DOS.
*/
 
/* From Ralph Brown's interrupt list, v.45.
Note: some OEMs, like Novell NDOS 7, Compaq DOS 3.31 and possibly
others return 0 OEM code, like IBM PC-DOS. There is nothing
I can do to overcome this.
*/
static struct _oem_info {
unsigned char oem_num;
const char * oem_name;
} dos_flavors[] = {
{0, "IBM PC-DOS"},
{1, "Compaq DOS"},
{2, "Microsoft DOS"},
{4, "AT&T DOS"},
{5, "Zenith DOS"},
{6, "Hewlett-Packard DOS"},
{7, "Groupe Bull DOS"},
{0xd, "Packard-Bell DOS"},
{0x16, "DEC DOS"},
{0x23, "Olivetti DOS"},
{0x28, "Texas Instruments DOS"},
{0x29, "Toshiba DOS"},
{0x33, "Novell Win3 device ID"},
{0x34, "MS Multimedia Win3 device ID"},
{0x35, "MS Multimedia Win3 device ID"},
{0x4d, "Hewlett-Packard DOS"},
{0x5e, "RxDOS"},
{0x66, "PTS-DOS"},
{0x99, "GenSoft Embedded DOS"},
{0xee, "DR-DOS"},
{0xef, "Novell DOS"},
{0xff, "Microsoft MS-DOS"},
{0, (char *)0}
};
 
static int getdosv_count = -1;
 
unsigned short
_get_dos_version(int true_version)
{
return 0x0500;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/getftime.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
#include <libc/dosio.h>
#include <errno.h>
#include <assert.h>
 
int getftime(int handle, struct ftime *ft)
{
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/gettime.c
0,0 → 1,16
#include <dos.h>
#include <assert.h>
 
#define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10)
 
void gettime( struct time *tp)
{
unsigned long tmp=__menuet__getsystemclock();
tp->ti_hour=tmp&0xff;
tp->ti_min=(tmp>>8)&0xff;
tp->ti_sec=(tmp>>16)&0xff;
tp->ti_hund=0;
BCD_TO_BIN(tp->ti_hour);
BCD_TO_BIN(tp->ti_min);
BCD_TO_BIN(tp->ti_sec);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/gettimeo.c
0,0 → 1,35
#include <time.h>
#include <assert.h>
 
#define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10)
 
int gettimeofday(struct timeval *tv, struct timezone *tz)
{
struct tm tmblk;
struct timeval tv_tmp;
unsigned long xtmp;
if (!tv) tv = &tv_tmp;
tv->tv_usec=0;
xtmp=__menuet__getsystemclock();
tmblk.tm_sec = (xtmp>>16)&0xff;
tmblk.tm_min = (xtmp>>8)&0xff;
tmblk.tm_hour = xtmp&0xff;
BCD_TO_BIN(tmblk.tm_sec);
BCD_TO_BIN(tmblk.tm_min);
BCD_TO_BIN(tmblk.tm_hour);
__asm__ __volatile__("int $0x40":"=a"(xtmp):"0"(29));
tmblk.tm_mday = (xtmp>>16)&0xff;
tmblk.tm_mon = ((xtmp>>8)&0xff)-1;
tmblk.tm_year = ((xtmp&0xff)+2000)-1900;
tmblk.tm_wday = tmblk.tm_yday = tmblk.tm_gmtoff = 0;
tmblk.tm_zone = 0;
tmblk.tm_isdst = -1;
tv->tv_sec = mktime(&tmblk);
if(tz)
{
struct tm *tmloc = localtime(&(tv->tv_sec));
tz->tz_minuteswest = - tmloc->tm_gmtoff / 60;
tz->tz_dsttime = tmloc->tm_isdst;
}
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/osflavor.c
0,0 → 1,4
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
 
const char *_os_flavor;
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/osmajor.c
0,0 → 1,4
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
 
unsigned short _osmajor;
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/osminor.c
0,0 → 1,4
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
 
unsigned short _osminor;
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/remotdrv.c
0,0 → 1,20
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* This is file REMOTDRV.C
*
* Copyright (c) 1994, 1995 Eli Zaretskii <eliz@is.elta.co.il>
*
* This software may be used freely so long as this copyright notice is
* left intact. There is no warranty on this software.
*
*/
#include <errno.h>
#include <dos.h>
#include <libc/dosio.h>
int _is_remote_drive(int c)
{
return 0;
}
 
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/remothdl.c
0,0 → 1,20
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/* This is file REMOTHDL.C */
/*
* Copyright (c) 1994 Eli Zaretskii <eliz@is.elta.co.il>
*
* This software may be used freely so long as this copyright notice is
* left intact. There is no warranty on this software.
*
*/
 
#include <errno.h>
#include <libc/dosio.h>
 
int _is_remote_handle(int);
 
int
_is_remote_handle(int fhandle)
{
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/setcbrk.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
#include <assert.h>
 
int setcbrk(int v)
{
unimpl();
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/setdate.c
0,0 → 1,7
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
#include <assert.h>
 
void setdate( struct date *dateblk)
{
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/setftime.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
#include <libc/dosio.h>
#include <errno.h>
#include <assert.h>
 
int setftime(int handle, struct ftime *ft)
{
return -EPERM;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos/settime.c
0,0 → 1,7
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <dos.h>
#include <assert.h>
 
void settime( struct time *tp)
{
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos_emu/Makefile
0,0 → 1,3
THIS_SRCS = dosemu.c curdir.c emu_init.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/dos/dos_emu/curdir.c
0,0 → 1,73
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
extern char __curdir_buf[1024];
 
char* __get_curdir(void) {return __curdir_buf;}
 
static void ___chdir(char* dest, const char* src)
{
// handle absolute paths
if (src[0]=='/')
{
strcpy(dest,src);
return;
}
// handle relative paths
char* ptr = dest + strlen(dest);
while (*src)
{
if (src[0] == '.' && src[1] == 0)
break;
if (src[0] == '.' && src[1] == '/')
{++src;++src;continue;}
if (src[0] == '.' && src[1] == '.' &&
(src[2] == 0 || src[2] == '/'))
{
while (ptr > dest && ptr[-1] != '/')
--ptr;
++src;++src;
if (*src == 0) break;
++src;
continue;
}
*ptr++ = '/';
if (*src == '/') ++src;
while (*src && *src!='/') *ptr++ = *src++;
}
*ptr = 0;
}
 
void __chdir(const char* path)
{
___chdir(__curdir_buf,path);
}
 
static char __libc_combine_buffer[1024];
char* __libc_combine_path(const char* c)
{
strcpy(__libc_combine_buffer,__curdir_buf);
___chdir(__libc_combine_buffer,c);
return __libc_combine_buffer;
}
 
 
#ifdef __TEST_IN_DOS__
 
int main(void)
{
init_dir_stack();
printf("|%s|\n",__get_curdir());
__chdir("jp/1/2/3");
printf("|%s|\n",__get_curdir());
__chdir("/jp/1/2/3");
printf("|%s|\n",__get_curdir());
__chdir("../4");
printf("|%s|\n",__get_curdir());
__chdir("./../..");
printf("|%s|\n",__get_curdir());
printf("Combined=|%s|\n",combine_path("./abc/def/../../../rd/2"));
return 0;
}
#endif
/programs/develop/libraries/menuetlibc/src/libc/dos/dos_emu/dosemu.c
0,0 → 1,238
#include "dosemuin.h"
#include <errno.h>
 
static char _io_filename[256];
 
static inline int sys_systree(struct systree_info * i,int * EBX)
{
int d0,d1;
__asm__ __volatile__("int $0x40"
:"=a"(d0),"=b"(d1)
:"0"(70),"1"((unsigned long)i)
:"memory");
if(EBX) *EBX=d1;
return d0;
}
 
int dosemu_file_exists(const char * filename)
{
struct systree_info finf;
struct bdfe_item attr;
finf.command = 5;
finf.file_offset_low = 0;
finf.file_offset_high = 0;
finf.size = 0;
finf.data_pointer = (__u32)&attr;
finf._zero = 0;
finf.nameptr = filename;
if (sys_systree(&finf,NULL)!=0)
return -1;
return (int)attr.filesize_low;
}
 
int dosemu_createtrunc(const char * filename)
{
struct systree_info finf;
finf.command = 2;
finf.file_offset_low = finf.file_offset_high = 0;
finf.size = 0;
finf.data_pointer = 0;
finf._zero = 0;
finf.nameptr = filename;
if (sys_systree(&finf,NULL))
return -1;
return 0;
}
 
_io_struct * dosemu_getiostruct(int handle)
{
if(handle<0 || handle>=_MAX_HANDLES) return NULL;
if(_io_handles[handle].oflags==-1) return NULL;
return _io_handles+handle;
}
 
int dosemu_allochandle(void)
{
int i;
for(i=0;i<_MAX_HANDLES;i++)
if(_io_handles[i].oflags==-1) return i;
return -1;
}
 
int dosemu_freehandle(int i)
{
if(i<0) return;
_io_handles[i].oflags=-1;
}
 
int dosemu_fileread(_io_struct * sh,char * buffer,int count)
{
struct systree_info finf;
int res,ebx;
finf.command = 0;
finf.file_offset_low = sh->pointer;
finf.file_offset_high = 0;
finf.size = count;
finf.data_pointer = (__u32)buffer;
finf._zero = 0;
finf.nameptr = sh->filename;
res = sys_systree(&finf,&ebx);
if (res != 0 && res != 6)
return -1;
sh->pointer += ebx;
return ebx;
}
 
int dosemu_filewrite(_io_struct * sh,char * buffer,int count)
{
struct systree_info finf;
int res,ebx;
finf.command = 3;
finf.file_offset_low = sh->pointer;
finf.file_offset_high = 0;
finf.size = count;
finf.data_pointer = (__u32)buffer;
finf._zero = 0;
finf.nameptr = sh->filename;
res = sys_systree(&finf,&ebx);
if (res != 0 && res != 6)
return -1;
sh->pointer += ebx;
if (sh->size < sh->pointer)
sh->size = sh->pointer;
return ebx;
}
 
int dosemu_iosize(int handle)
{
_io_struct * sh=dosemu_getiostruct(handle);
if(!sh) return -1;
return sh->size;
}
 
int dosemu_filesize(char * filename)
{
return dosemu_file_exists(filename);
}
 
static char fn_buf[256];
 
int dosemu_open(char * filename,int oflags)
{
int baseflags,h,fsize;
_fixpath(filename,_io_filename);
baseflags=oflags&(O_RDONLY|O_WRONLY|O_RDWR);
h=dosemu_allochandle();
fsize=dosemu_file_exists(_io_filename);
if(oflags & O_CREAT)
{
int creatflags=oflags & (O_EXCL|O_TRUNC);
if(creatflags & O_EXCL)
{
if(fsize>=0)
{
dosemu_freehandle(h);
return -1;
}
}
if(fsize<0 || (creatflags&O_TRUNC))
{
if(dosemu_createtrunc(_io_filename)<0)
{
dosemu_freehandle(h);
return -1;
}
fsize=0;
}
}
else if (fsize<0)
{
dosemu_freehandle(h);
return -1;
}
_io_handles[h].oflags=oflags;
_io_handles[h].size=fsize;
_io_handles[h].pointer=0;
switch (baseflags)
{
case O_RDONLY:_io_handles[h].flags=_IO_READ;break;
case O_WRONLY:_io_handles[h].flags=_IO_WRITE;break;
case O_RDWR:_io_handles[h].flags=_IO_READ|_IO_WRITE;break;
default:dosemu_freehandle(h);return -1;
}
strcpy(_io_handles[h].filename,_io_filename);
return h;
}
 
int dosemu_tell(int handle)
{
_io_struct * sh=dosemu_getiostruct(handle);
if(!sh) return -1;
return sh->pointer;
}
int dosemu_lseek(int handle,long offset,int origin)
{
int newpointer=0;
_io_struct *sh=dosemu_getiostruct(handle);
if(!sh)return -1;
if(handle==0 || handle==1 || handle==2 || handle==3) return -1;
switch(origin)
{
case SEEK_SET: newpointer=offset;break;
case SEEK_CUR: newpointer=sh->pointer+offset;break;
case SEEK_END: newpointer=sh->size+offset;break;
}
if(newpointer<0)return -1;
sh->pointer=newpointer;
return newpointer;
}
 
int dosemu_read( int handle, void *buffer, unsigned int count )
{
_io_struct *sh=dosemu_getiostruct(handle);
if(!sh)return -1;
if(!(sh->flags&_IO_READ)) return -1;
return dosemu_fileread(sh,buffer,count);
}
 
int dosemu_write( int handle, void *buffer, unsigned int count )
{
_io_struct *sh=dosemu_getiostruct(handle);
int k;
if(!sh)return -1;
if(!(sh->flags&_IO_WRITE)) return -1;
return dosemu_filewrite(sh,buffer,count);
}
 
int dosemu_close( int handle )
{
_io_struct *sh=dosemu_getiostruct(handle);
if(!sh)return -1;
dosemu_freehandle(handle);
return 0;
}
 
void _dosemu_flush(int handle)
{}
 
int dosemu_truncate(int fd, off_t where)
{
struct systree_info finf;
int res;
_io_struct* sh = dosemu_getiostruct(fd);
if (!sh) return EBADF;
if (!(sh->flags & _IO_WRITE)) return EBADF;
finf.command = 4;
finf.file_offset_low = where;
finf.file_offset_high = 0;
finf.size = 0;
finf.data_pointer = 0;
finf._zero = 0;
finf.nameptr = sh->filename;
res = sys_systree(&finf,NULL);
if (res == 8) return ENOSPC;
if (res) return EACCES;
sh->size = where;
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos_emu/dosemuin.h
0,0 → 1,26
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<fcntl.h>
#include<errno.h>
#include<menuet/os.h>
 
#define _MAX_HANDLES 64
 
#define _IO_READ 1
#define _IO_WRITE 2
#define _IO_BUFDIRTY 4
 
#define IODEBUG(x...) /* */
 
typedef struct
{
int size;
int oflags;
int flags;
int pointer;
char filename[512];
} _io_struct;
 
extern _io_struct _io_handles[_MAX_HANDLES];
/programs/develop/libraries/menuetlibc/src/libc/dos/dos_emu/emu_init.c
0,0 → 1,32
#include "dosemuin.h"
 
_io_struct _io_handles[_MAX_HANDLES];
 
void dosemu_inithandles(void)
{
int i;
for(i=0;i<_MAX_HANDLES;i++)
_io_handles[i].oflags=-1;
_io_handles[0].oflags=1;
_io_handles[1].oflags=1;
_io_handles[2].oflags=1;
_io_handles[3].oflags=1;
}
 
/* If you want to do some actions for closing handles,
you must add it to this function
and uncomment call to atexit(dosemu_atexit) in crt1.c.
In this case I recommend to implement all referenced functions
here (and not in dosemu.c) to avoid linking dosemu.o
in programs which do not use I/O system. - diamond */
//void dosemu_atexit()
//{}
 
char __curdir_buf[1024];
extern char __menuet__app_path_area[];
 
void init_dir_stack(void)
{
strcpy(__curdir_buf,__menuet__app_path_area);
*strrchr(__curdir_buf,'/') = 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/dos_emu/fslayer.c
0,0 → 1,287
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<errno.h>
#include<fcntl.h>
#include<menuet/os.h>
 
struct systree_blk
{
unsigned long cmd,pos,blks;
void * data,* work;
char name[256];
} __attribute__((packed));
 
typedef struct EMU_FILE
{
int handle;
unsigned long size;
unsigned long pos;
unsigned long mode;
unsigned long current_sector;
unsigned long size_sectors;
char * write_buf;
unsigned long write_bufsize;
char rd_buffer[512];
char name[256];
unsigned char dirty;
} EMU_FILE;
 
#define _MAX_HANDLES 64
 
static EMU_FILE * EMU_file_table[_MAX_HANDLES];
static char systree_work_area[16384+512];
static volatile struct systree_blk sblk;
static volatile int S_eax,S_ebx;
 
static inline int EMU_alloc_handle(void)
{
register int i;
for(i=0;i<_MAX_HANDLES;i++)
if(!EMU_file_table[i])
{
EMU_file_table[i]=(EMU_FILE *)malloc(sizeof(EMU_FILE));
if(!EMU_file_table[i]) return -ENOMEM;
return i;
}
return -EAGAIN;
}
 
static inline int EMU_systree_cmd(void)
{
__asm__ __volatile__("int $0x40"
:"=a"(S_eax),"=b"(S_ebx)
:"0"(58),"1"((void *)&sblk));
return S_eax;
}
 
static int EMU_loadsector(EMU_FILE * filp)
{
sblk.cmd=0;
sblk.pos=filp->current_sector;
sblk.blks=1;
sblk.data=filp->rd_buffer;
sblk.work=systree_work_area;
memcpy((void *)&sblk.name,(const void *)filp->name,strlen(filp->name)+1);
return EMU_systree_cmd();
}
 
static int EMU_fsync(EMU_FILE * filp)
{
if(filp->mode==O_RDONLY) return 0;
if(!filp->dirty) return 0;
filp->dirty=0;
sblk.cmd=1;
sblk.pos=0;
sblk.blks=filp->size;
sblk.data=filp->write_buf;
sblk.work=systree_work_area;
memcpy((void *)sblk.name,(const void *)filp->name,strlen(filp->name)+1);
return EMU_systree_cmd();
}
 
static inline int EMU_realloc_buf(EMU_FILE * filp,unsigned long newsize)
{
char * n;
newsize=(newsize+511)&~511;
if(filp->write_bufsize==newsize) return 0;
n=(char *)realloc(filp->write_buf,newsize);
if(!n) return -ENOSPC;
filp->write_buf=n;
filp->write_bufsize=newsize;
filp->dirty=1;
return 0;
}
 
static int EMU_createtrunc(char * fname)
{
sblk.cmd=1;
sblk.pos=0;
sblk.blks=0;
sblk.data=sblk.work=systree_work_area;
memcpy((void *)sblk.name,(const void *)fname,strlen(fname)+1);
return EMU_systree_cmd();
}
 
static int EMU_getfsize(char * fname,unsigned long * sizep)
{
sblk.cmd=0;
sblk.pos=0;
sblk.blks=1;
sblk.data=systree_work_area+16384;
sblk.work=systree_work_area;
memcpy((void *)sblk.name,(const void *)fname,strlen(fname)+1);
if(EMU_systree_cmd()!=0) return -EINVAL;
if(sizep) *sizep=(unsigned long)S_ebx;
return 0;
}
 
static int EMU_open(char * fname,int mode)
{
EMU_FILE * filp;
register int hid;
unsigned long iomode;
hid=EMU_alloc_handle();
if(hid<0) return hid;
filp=EMU_file_table[hid];
filp->handle=hid;
iomode=mode&(O_RDONLY|O_WRONLY|O_RDWR);
memcpy((void *)filp->name,(const void *)fname,strlen(fname)+1);
strupr(filp->name);
filp->mode=iomode;
if(mode&O_CREAT)
{
int createflags=mode&(O_TRUNC|O_EXCL);
if(createflags&O_EXCL)
{
unsigned long psz=0;
if(EMU_getfsize(filp->name,&psz)==0)
{
free(EMU_file_table[hid=filp->handle]);
EMU_file_table[hid]=NULL;
return -EEXIST;
}
}
if(createflags&O_TRUNC)
{
EMU_createtrunc(filp->name);
}
}
if(iomode==O_RDONLY)
{
hid=EMU_getfsize(filp->name,&filp->size);
if(hid<0)
{
free(EMU_file_table[hid=filp->handle]);
EMU_file_table[hid]=NULL;
return -ENOENT;
}
filp->current_sector=0;
if(EMU_loadsector(filp)<0) filp->current_sector=-1UL;
filp->mode=O_RDONLY;
filp->size_sectors=(filp->size+511)/512;
filp->write_bufsize=0;
filp->dirty=0;
return filp->handle;
}
if(iomode==O_WRONLY)
{
hid=EMU_getfsize(filp->name,&filp->size);
if(hid<0)
{
BAD_WRO:
free(EMU_file_table[hid=filp->handle]);
EMU_file_table[hid]=NULL;
return -ENOENT;
}
filp->current_sector=-1UL;
filp->mode=O_WRONLY;
filp->size_sectors=0;
filp->write_bufsize=(filp->size+511)&~511;
filp->write_buf=(char *)malloc(filp->write_bufsize);
if(!filp->write_buf)
{
free(filp->write_buf);
goto BAD_WRO;
}
sblk.cmd=0;
sblk.pos=0;
sblk.blks=filp->write_bufsize/512;
sblk.data=filp->write_buf;
sblk.work=systree_work_area;
if(EMU_systree_cmd()!=0) goto BAD_WRO1;
return filp->handle;
}
hid=EMU_getfsize(filp->name,&filp->size);
if(hid<0)
{
BAD_WRO1:
free(EMU_file_table[hid=filp->handle]);
EMU_file_table[hid]=NULL;
return -ENOENT;
}
filp->current_sector=-1UL;
filp->mode=O_RDWR;
filp->size_sectors=0;
filp->write_bufsize=(filp->size+511)&~511;
filp->write_buf=(char *)malloc(filp->write_bufsize);
if(!filp->write_buf)
{
free(filp->write_buf);
goto BAD_WRO1;
}
sblk.cmd=0;
sblk.pos=0;
sblk.blks=filp->write_bufsize/512;
sblk.data=filp->write_buf;
sblk.work=systree_work_area;
if(EMU_systree_cmd()!=0) goto BAD_WRO1;
return filp->handle;
}
 
static int EMU_close(EMU_FILE * filp)
{
int hid;
if(!filp) return -ENOENT;
if(EMU_file_table[hid=filp->handle]!=filp) return -EBADF;
if(filp->write_buf) free(filp->write_buf);
free(filp);
EMU_file_table[hid]=NULL;
return 0;
}
 
static int EMU_lseek(EMU_FILE * filp,unsigned long off,int whence)
{
unsigned long newpos;
switch(whence)
{
case SEEK_SET:
newpos=off;
break;
case SEEK_CUR:
newpos=filp->pos+off;
break;
case SEEK_END:
newpos=filp->size+off-1;
break;
}
if(newpos>=filp->size) return -1;
filp->pos=newpos;
return filp->pos;
}
 
static int EMU_read(EMU_FILE * filp,unsigned long size,void * buf)
{
int icount,curr_sector,curr_sector_ofs,n;
int nbufbytes,totalremaining;
if(filp->pos+count>filp->size)
count=filp->size-filp->pos;
if(filp->mode==O_RDWR)
{
memcpy(buffer,filp->write_buf+filp->pos,count);
filp->pos+=count;
return count;
}
icount=count;
while(count>0)
{
if(filp->pos>=filp->size) return icount=count;
curr_sector=sh->pointer>>9;
curr_sector_ofs=sh->pointer&511;
n=count;
if(sh->bufsector==-1 || curr_sector!=sh->bufsector)
{
if(dosemu_loadcurrsector(sh)==-1) return -1;
}
nbufbytes=512-curr_sector_ofs;
totalremaining=sh->size-sh->pointer;
if(nbufbytes>totalremaining) nbufbytes=totalremaining;
if(n>nbufbytes) n=nbufbytes;
memcpy(buffer,&sh->buf[curr_sector_ofs],n);
buffer+=n;
count-=n;
sh->pointer+=n;
}
return icount;
}
}
/programs/develop/libraries/menuetlibc/src/libc/dos/errno/Makefile
0,0 → 1,3
THIS_SRCS = doserr2e.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/dos/errno/doserr2e.c
0,0 → 1,28
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include <libc/dosio.h>
 
static unsigned char map[] = {
/* 00-07 */ 0, EINVAL, ENOENT, ENOENT, ENFILE, EACCES, EBADF, EFAULT,
/* 08-0f */ ENOMEM, EFAULT, EFAULT, EINVAL, EINVAL, EINVAL, EINVAL, ENODEV,
/* 10-17 */ EBUSY, EXDEV, ENMFILE, EROFS, ENXIO, ENODEV, EINVAL, EINVAL,
/* 18-1f */ EINVAL, EIO, EIO, EIO, EIO, EIO, EIO, EPERM,
/* 20-27 */ EACCES, EACCES, ENXIO, EBADF, ENOLCK, EINVAL, EIO, ENOSPC,
/* 28-2f */ EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL,
/* 30-37 */ EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EBUSY, ENXIO,
/* 38-3f */ EINVAL, EIO, EIO, EIO, EIO, EAGAIN, EINVAL, ENOSPC,
/* 40-47 */ EINVAL, EACCES, ENXIO, EINVAL, EINVAL, EINVAL, EBUSY, ENXIO,
/* 48-4f */ EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL,
/* 50-57 */ EEXIST, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL,
/* 57-5f */ EINVAL, ENOSYS, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL,
/* 60-67 */ EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, ENODEV, EINVAL, EINVAL,
/* 68-6f */ ENODEV, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL, EINVAL
};
 
int
__doserr_to_errno(int doserr)
{
if (doserr >= 0 && doserr < sizeof(map)/sizeof(map[0]))
return map[doserr];
return EINVAL;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/Makefile
0,0 → 1,6
THIS_SRCS = _chmod.c _close.c _creat.c crlf2nl.c dosio.c doslock.c \
dosunloc.c fmode.c lock.c _open.c putpath.c _read.c setmode.c \
tell.c unlock.c _write.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
 
/programs/develop/libraries/menuetlibc/src/libc/dos/io/_chmod.c
0,0 → 1,17
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <io.h>
#include <errno.h>
#include <libc/dosio.h>
#include <assert.h>
#include <stdio.h>
#include <fcntl.h>
int _chmod(const char *filename, int func, ...)
{
int i;
i=open(filename,O_RDONLY);
if(i<0) return -1;
close(i);
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/_close.c
0,0 → 1,25
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
#include <errno.h>
#include <io.h>
#include <sys/fsext.h>
 
#include <libc/dosio.h>
 
#include <menuet/os.h>
 
int _close(int handle)
{
__FSEXT_Function *func = __FSEXT_get_function(handle);
if (func)
{
int rv;
if (func(__FSEXT_close, &rv, &handle))
{
__FSEXT_set_function(handle, 0);
return rv;
}
__FSEXT_set_function(handle, 0);
}
return dosemu_close(handle);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/_creat.c
0,0 → 1,12
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <fcntl.h>
#include <errno.h>
#include <io.h>
#include <libc/dosio.h>
#include <sys/fsext.h>
 
int _creat(const char* filename, int attrib)
{
return _open(filename,attrib|O_CREAT);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/_open.c
0,0 → 1,18
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <io.h>
#include <libc/dosio.h>
#include <sys/fsext.h>
#define FSLAYER
#include <menuet/os.h>
 
int _open(const char* filename, int oflag)
{
int rv;
if (__FSEXT_call_open_handlers(__FSEXT_open, &rv, &filename))
return rv;
return dosemu_open(filename,oflag);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/_read.c
0,0 → 1,22
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <io.h>
#include <sys/fsext.h>
 
#include <libc/dosio.h>
#define FSLAYER
#include <menuet/os.h>
 
int _read(int handle, void* buffer, size_t count)
{
__FSEXT_Function *func = __FSEXT_get_function(handle);
if (func)
{
int rv;
if (func(__FSEXT_read, &rv, &handle)) return rv;
}
return dosemu_read(handle,buffer,count);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/_write.c
0,0 → 1,22
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <io.h>
#include <sys/fsext.h>
 
#include <libc/dosio.h>
#define FSLAYER
#include <menuet/os.h>
 
int _write(int handle, const void* buffer, size_t count)
{
__FSEXT_Function *func = __FSEXT_get_function(handle);
if (func)
{
int rv;
if (func(__FSEXT_write, &rv, &handle)) return rv;
}
return dosemu_write(handle,buffer,count);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/crlf2nl.c
0,0 → 1,20
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <io.h>
 
ssize_t
crlf2nl(char *buf, ssize_t len)
{
char *bp = buf;
int i=0;
while (len--)
{
if (*bp != 13)
{
*buf++ = *bp;
i++;
}
bp++;
}
return i;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/dosio.c
0,0 → 1,27
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
 
#include <libc/dosio.h>
#include <libc/bss.h>
 
static char init_file_handle_modes[20] = {
O_TEXT,
O_TEXT,
O_TEXT,
O_BINARY,
O_BINARY
};
 
static int dosio_bss_count = -1;
static size_t count=20; /* DOS default limit */
 
char *__file_handle_modes = init_file_handle_modes;
 
void
__file_handle_set(int fd, int mode)
{
/* Fill in the value */
__file_handle_modes[fd] = mode;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/doslock.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <io.h>
#include <assert.h>
 
int _dos_lock(int _fd, long _offset, long _length)
{
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/dosunloc.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <io.h>
#include <assert.h>
 
int _dos_unlock(int _fd, long _offset, long _length)
{
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/fmode.c
0,0 → 1,5
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <fcntl.h>
#include <io.h>
 
int _fmode = O_TEXT;
/programs/develop/libraries/menuetlibc/src/libc/dos/io/lock.c
0,0 → 1,11
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <io.h>
#include <errno.h>
#include <assert.h>
 
int
lock(int fd, long offset, long length)
{
unimpl();
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/putpath.c
0,0 → 1,19
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/dosio.h>
#include <libc/farptrgs.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
 
void
_put_path(const char *path)
{
_put_path2(path, 0);
}
 
void
_put_path2(const char *path, int offset)
{
unimpl();
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/setmode.c
0,0 → 1,16
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <sys/exceptn.h>
#include <errno.h>
#include <fcntl.h>
#include <io.h>
 
#include <libc/dosio.h>
#include <assert.h>
 
void (*__setmode_stdio_hook)(int fd, int mode); /* BSS to zero */
 
int setmode(int handle, int mode)
{
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/tell.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <errno.h>
#include <io.h>
#include <unistd.h>
 
off_t tell(int _file)
{
return dosemu_tell(_file);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/io/unlock.c
0,0 → 1,11
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <io.h>
#include <errno.h>
#include <assert.h>
 
int
unlock(int fd, long offset, long length)
{
unimpl();
}
 
/programs/develop/libraries/menuetlibc/src/libc/dos/process/Makefile
0,0 → 1,4
THIS_SRCS = chkv2prg.c dosexec.c spawnl.c spawnle.c spawnlp.c spawnlpe.c \
spawnv.c spawnvp.c spawnvpe.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/dos/process/chkv2prg.c
0,0 → 1,137
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdlib.h>
#include <sys/system.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
 
#define STUB_INFO_MAGIC "StubInfoMagic!!"
 
static _v2_prog_type type;
static int type_initialized = 0;
 
static
const _v2_prog_type *_check_v2_prog_internal (int pf);
 
const _v2_prog_type *_check_v2_prog(const char *program, int pf)
{
const _v2_prog_type *prog_type;
 
if (type_initialized && type.stubinfo)
free(type.stubinfo);
type_initialized = 1;
 
memset(&type, 0, sizeof(type));
 
if (program)
{
pf = open(program, O_RDONLY|O_BINARY);
if (pf < 0)
return &type;
}
 
prog_type = _check_v2_prog_internal(pf);
 
if (program)
close(pf);
 
if (prog_type)
type.valid = 1;
return &type;
}
 
static
const _v2_prog_type *_check_v2_prog_internal (int pf)
{
unsigned short header[5];
lseek(pf, 0, SEEK_SET);
if (read(pf, header, sizeof(header)) != sizeof(header))
return NULL;
if (header[0] == 0x010b || header[0] == 0x014c)
{
unsigned char firstbytes[1];
unsigned long coffhdr[40];
 
/* Seems to be an unstubbed COFF. See what the first opcode
is to determine if it's v1.x or v2 COFF (or an impostor).
 
FIXME: the code here assumes that any COFF that's not a V1
can only be V2. What about other compilers that use COFF? */
type.object_format = _V2_OBJECT_FORMAT_COFF;
if (lseek(pf, 2, 1) < 0
|| read(pf, coffhdr, sizeof(coffhdr)) != sizeof(coffhdr)
|| lseek(pf, coffhdr[10 + 5], 0) < 0
|| read(pf, firstbytes, 1) != 1) /* scnptr */
/* "Aha! An impostor!" (The Adventure game) */
type.object_format = _V2_OBJECT_FORMAT_UNKNOWN;
else if (firstbytes[0] != 0xa3) /* opcode of movl %eax, 0x12345678 (V1) */
type.version.v.major = 2;
else
type.version.v.major = 1;
type.exec_format = _V2_EXEC_FORMAT_COFF;
}
else if (header[0] == 0x5a4d) /* "MZ" */
{
char go32stub[9];
unsigned long coff_start = (unsigned long)header[2]*512L;
unsigned long exe_start;
type.exec_format = _V2_EXEC_FORMAT_EXE;
if (header[1])
coff_start += (long)header[1] - 512L;
exe_start = (unsigned long)header[4]*16L;
if (lseek(pf, exe_start, SEEK_SET) != exe_start)
return NULL;
if (read(pf, go32stub, 8) != 8)
return NULL;
go32stub[8] = 0;
if (strcmp(go32stub, "go32stub") == 0)
{
type.version.v.major = 2;
type.object_format = _V2_OBJECT_FORMAT_COFF;
type.exec_format = _V2_EXEC_FORMAT_STUBCOFF;
}
else
{
int stub_offset;
char magic[16];
int struct_length;
unsigned short coff_id;
type.version.v.major = 1;
if (lseek(pf, coff_start - 4, SEEK_SET) != coff_start-4)
return NULL;
if (read(pf, &stub_offset, 4) != 4)
return NULL;
if (read(pf, &coff_id, 2) != 2)
return NULL;
if (coff_id == 0x010b || coff_id == 0x014c)
{
type.object_format = _V2_OBJECT_FORMAT_COFF;
type.exec_format = _V2_EXEC_FORMAT_STUBCOFF;
}
if (lseek(pf, stub_offset, 0) != stub_offset)
return NULL;
if (read(pf, magic, 16) != 16)
return NULL;
if (memcmp(STUB_INFO_MAGIC, magic, 16) == 0)
{
if (read(pf, &struct_length, 4) != 4)
return NULL;
type.stubinfo = (_v1_stubinfo *)malloc(struct_length);
memcpy(type.stubinfo->magic, magic, 16);
type.stubinfo->struct_length = struct_length;
if (read(pf, type.stubinfo->go32, struct_length - 20)
!= struct_length - 20)
return NULL;
type.has_stubinfo = 1;
}
}
}
else if (header[0] == 0x2123) /* "#!" */
{
type.exec_format = _V2_EXEC_FORMAT_UNIXSCRIPT;
}
return &type;
}
 
/programs/develop/libraries/menuetlibc/src/libc/dos/process/dosexec.c
0,0 → 1,102
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <menuet/os.h>
#include <sys/stat.h>
 
int _dos_exec(const char *program, const char *args, char * const envp[])
{
return -1;
}
 
 
int _is_unixy_shell (const char *shellpath)
{
return -1;
}
 
int _is_dos_shell (const char *shellpath)
{
return -1;
}
 
int __dosexec_command_exec(const char *program, char **argv, char **envp)
{
return -1;
}
 
char * __dosexec_find_on_path(const char *program, char *envp[], char *buf)
{
return NULL;
}
 
 
static void build_args(char * dstbuf,char * const argv[],int argc)
{
int i,j;
for(i=0;i<argc;i++)
{
j=strlen(argv[i]);
if(i==(argc-1))
sprintf(dstbuf,"%s",argv[i]);
else
sprintf(dstbuf,"%s ",argv[i]);
dstbuf+=j;
}
}
 
int __spawnve(int mode, const char *path, char *const argv[], char *const envp[])
{
char * buffer_for_args;
int ap,asz;
struct systree_info st_info;
int res;
fflush(stdout);
if(!path)
{
errno=EINVAL;
return -1;
}
if(strlen(path)>FILENAME_MAX-1)
{
errno = ENAMETOOLONG;
return -1;
}
for(ap=0,asz=10;argv[ap]!=NULL;ap++)
{
asz+=strlen(argv[ap])+1;
}
if(ap)
{
buffer_for_args=malloc(asz);
if(!buffer_for_args)
{
errno=ENOMEM;
return -1;
}
memset(buffer_for_args,0,asz);
build_args(buffer_for_args,argv,ap);
} else buffer_for_args=NULL;
st_info.command = 7;
st_info.file_offset_low = 0;
st_info.file_offset_high = (__u32)buffer_for_args;
st_info.size = 0;
st_info.data_pointer = 0;
st_info._zero = 0;
//_fix_path(path,st_info.name);
st_info.nameptr = path;
res = __kolibri__system_tree_access(&st_info);
if (res == -5)
errno = ENOENT;
else if (res == -31)
errno = ENOEXEC;
else if (res == -30 || res == -32)
errno = ENOMEM;
else if (res < 0)
errno = EINVAL;
free(buffer_for_args);
if(mode==0x1BADB002) exit(0);
return (res>0)?res:-1;
}
/programs/develop/libraries/menuetlibc/src/libc/dos/process/spawnl.c
0,0 → 1,12
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <libc/unconst.h>
#include <process.h>
 
extern char **environ;
 
int spawnl(int mode, const char *path, const char *argv0, ...)
{
return spawnve(mode, path, unconst(&argv0,char * const *), environ);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/process/spawnle.c
0,0 → 1,13
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <libc/unconst.h>
#include <process.h>
#include <libc/dosexec.h>
 
int spawnle(int mode, const char *path, const char *argv0, ... /*, const char **envp */)
{
scan_ptr();
return spawnve(mode, path, unconst(&argv0,char * const *),
unconst(ptr,char * const *));
}
/programs/develop/libraries/menuetlibc/src/libc/dos/process/spawnlp.c
0,0 → 1,13
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <libc/unconst.h>
#include <process.h>
 
extern char **environ;
 
int spawnlp(int mode, const char *path, const char *argv0, ...)
{
return spawnvpe(mode, path, unconst(&argv0,char * const *),
(char * const *)environ);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/process/spawnlpe.c
0,0 → 1,13
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <libc/unconst.h>
#include <process.h>
#include <libc/dosexec.h>
 
int spawnlpe(int mode, const char *path, const char *argv0, ... /*, const char **envp */)
{
scan_ptr();
return spawnvpe(mode, path, unconst(&argv0,char * const *),
unconst(ptr,char * const *));
}
/programs/develop/libraries/menuetlibc/src/libc/dos/process/spawnv.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <process.h>
 
extern char **environ;
 
int spawnv(int mode, const char *path, char *const argv[])
{
return spawnve(mode, path, (char * const *)argv, environ);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/process/spawnvp.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <process.h>
 
extern char **environ;
 
int spawnvp(int mode, const char *path, char *const argv[])
{
return spawnvpe(mode, path, (char * const *)argv, environ);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/process/spawnvpe.c
0,0 → 1,21
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <process.h>
#include <errno.h>
#include <libc/unconst.h>
#include <libc/dosexec.h>
 
int spawnvpe(int mode, const char *path, char *const argv[], char *const envp[])
{
char rpath[300];
union { char * const *cpcp; char **cpp; } u;
u.cpcp = envp;
 
if (!__dosexec_find_on_path(path, u.cpp, rpath))
{
errno = ENOENT;
return -1;
}
else
return spawnve(mode, rpath, argv, envp);
}
/programs/develop/libraries/menuetlibc/src/libc/dos/sys/Makefile
0,0 → 1,8
all:
make -C timeb
 
depend:
make -C timeb depend
 
clean:
make -C timeb clean
/programs/develop/libraries/menuetlibc/src/libc/dos/sys/timeb/Makefile
0,0 → 1,3
THIS_SRCS = ftime.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/dos/sys/timeb/ftime.c
0,0 → 1,21
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <time.h>
#include <sys/timeb.h>
 
int
ftime(struct timeb *tp)
{
struct timeval tv;
struct timezone tz;
 
if (gettimeofday(&tv, &tz) < 0)
return -1;
 
tp->time = tv.tv_sec;
tp->millitm = tv.tv_usec / 1000;
tp->timezone = tz.tz_minuteswest;
tp->dstflag = tz.tz_dsttime;
 
return 0;
}