Skip to content
Snippets Groups Projects
Commit 4191d256 authored by rswindell's avatar rswindell
Browse files

Added more wrapper functions for Unix compatibility.

parent c32630a8
No related branches found
No related tags found
No related merge requests found
......@@ -68,12 +68,110 @@
#ifdef __unix__
struct termios current; // our current term settings
struct termios original; // old termios settings
struct timeval timeout = {0, 0}; // passed in select() call
fd_set inp; // ditto
static int beensetup = 0; // has _termios_setup() been called?
/****************************************************************************/
/* Wrapper for Win32 create/begin thread function */
/* Uses POSIX threads */
/****************************************************************************/
#ifdef _POSIX_THREADS
ulong _beginthread(void( *start_address )( void * )
,unsigned stack_size, void *arglist)
{
pthread_t thread;
pthread_attr_t attr;
pthread_attr_init(&attr); /* initialize attribute structure */
/* set thread attributes to PTHREAD_CREATE_DETACHED which will ensure
that thread resources are freed on exit() */
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
if(pthread_create(&thread
,&attr /* default attributes */
/* POSIX defines this arg as "void *(*start_address)" */
,(void *) start_address
,arglist)==0)
return((int) thread /* thread handle */);
return(-1); /* error */
}
#else
#error "Need _beginthread implementation for non-POSIX thread library."
#endif
/****************************************************************************/
/* Convert ASCIIZ string to upper case */
/****************************************************************************/
char* strupr(char* str)
{
char* p=str;
while(*p) {
*p=toupper(*p);
p++;
}
return(str);
}
/****************************************************************************/
/* Convert ASCIIZ string to lower case */
/****************************************************************************/
char* strlwr(char* str)
{
char* p=str;
while(*p) {
*p=tolower(*p);
p++;
}
return(str);
}
/****************************************************************************/
/* Reverse chars in string */
/****************************************************************************/
char* strrev(char* str)
{
char t, *i=str, *j=str+strlen(str);
while (i<j) {
t=*i; *(i++)=*(--j); *j=t;
}
return str;
}
/* This is a bit of a hack, but it works */
char* _fullpath(char* absPath, const char* relPath, size_t maxLength)
{
char *curdir = (char *) malloc(PATH_MAX+1);
if(curdir == NULL) {
strcpy(absPath,relPath);
return(absPath);
}
getcwd(curdir, PATH_MAX);
if(chdir(relPath)!=0) /* error, invalid dir */
strcpy(absPath,relPath);
else {
getcwd(absPath, maxLength);
chdir(curdir);
}
free(curdir);
return absPath;
}
/***************************************/
/* Console I/O Stuff (by Casey Martin) */
/***************************************/
static struct termios current; // our current term settings
static struct termios original; // old termios settings
static struct timeval timeout = {0, 0}; // passed in select() call
static fd_set inp; // ditto
static int beensetup = 0; // has _termios_setup() been called?
/*
I'm using a variable function here simply for the sake of speed. The
termios functions must be called before a kbhit() can be successful, so
......@@ -160,34 +258,9 @@ int getch(void)
#endif // __unix__
/****************************************************************************/
/* Convert ASCIIZ string to upper case */
/****************************************************************************/
#ifdef __unix__
char* strupr(char* str)
{
char* p=str;
while(*p) {
*p=toupper(*p);
p++;
}
return(str);
}
/****************************************************************************/
/* Convert ASCIIZ string to lower case */
/****************************************************************************/
char* strlwr(char* str)
{
char* p=str;
while(*p) {
*p=tolower(*p);
p++;
}
return(str);
}
#endif
/**************/
/* File Stuff */
/**************/
/****************************************************************************/
/* Returns the length of the file in 'filename' */
......
......@@ -42,6 +42,7 @@
int kbhit(void);
int getch(void);
#define ungetch(x) /* !need a wrapper for this */
#else /* DOS-Based */
......@@ -132,7 +133,13 @@
#define _rmdir(dir) rmdir(dir)
#define tell(fd) lseek(fd,0,SEEK_CUR)
char* _fullpath(char* absPath, const char* relPath
int sopen(char *fn, int access, int share);
long filelength(int fd);
char* strupr(char* str);
char* strlwr(char* str);
char* strrev(char* str);
char* _fullpath(char* absPath, const char* relPath
,size_t maxLength);
#elif defined(__MSDOS__)
......@@ -145,8 +152,6 @@
#endif
#ifndef BOOL
#define BOOL int
#endif
......@@ -168,13 +173,6 @@ extern "C" {
int unlock(int fd, long pos, int len);
#endif
#if defined(__unix__)
int sopen(char *fn, int access, int share);
long filelength(int fd);
char* strupr(char* str);
char* strlwr(char* str);
#endif
#if !defined(_MSC_VER) && !defined(__BORLANDC__)
char* ultoa(unsigned long val, char* str, int radix);
#endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment