lib/oswin9x.c

Go to the documentation of this file.
00001 /* Stuff that's specific for Win95 goes here. 
00002  *
00003  * This file is copyright 2002 Jim Kent, but license is hereby
00004  * granted for all use - public, private or commercial. */
00005 #include "common.h"
00006 #include <io.h>
00007 #include <direct.h>
00008 #include "portable.h"
00009 
00010 static char const rcsid[] = "$Id: oswin9x.c,v 1.8 2003/05/06 07:33:43 kate Exp $";
00011 
00012 /* Return how long the named file is in bytes. 
00013  * Return -1 if no such file. */
00014 off_t fileSize(char *fileName)
00015 {
00016 int fd;
00017 long size;
00018 fd = _open(fileName, _O_RDONLY, 0);
00019 if (fd < 0)
00020     return -1;
00021 size = _lseek(fd, 0L, SEEK_END);
00022 _close(fd);
00023 return size;
00024 }
00025 
00026 long clock1000()
00027 /* A millisecond clock. */
00028 {
00029 return clock() /* 1000/CLOCKS_PER_SEC */;   /* CLOCKS_PER_SEC == 1000 for windows */
00030 }
00031 
00032 long clock1()
00033 /* Second clock. */
00034 {
00035 return clock()/CLOCKS_PER_SEC;
00036 }
00037 
00038 void uglyfBreak()
00039 /* Go into debugger. */
00040 {
00041 __asm { int 3 } /* uglyf */
00042 }
00043 
00044 char *getCurrentDir()
00045 /* Return current directory. */
00046 {
00047 static char dir[_MAX_PATH];
00048 
00049 if( _getcwd( dir, _MAX_PATH ) == NULL )
00050     {
00051     warn("No current directory");
00052     return NULL;
00053     }
00054 return dir;
00055 }
00056 
00057 boolean setCurrentDir(char *newDir)
00058 /* Set current directory.  Return FALSE if it fails. */
00059 {
00060 if (_chdir(newDir) != 0)
00061     {
00062     warn("Unable to set dir %s", newDir);
00063     return FALSE;
00064     }
00065 return TRUE;
00066 }
00067 
00068 struct slName *listDir(char *dir, char *pattern)
00069 /* Return an alphabetized list of all files that match 
00070  * the wildcard pattern in directory. */
00071 {
00072 long hFile;
00073 struct _finddata_t fileInfo;
00074 struct slName *list = NULL, *name;
00075 boolean otherDir = FALSE;
00076 char *currentDir;
00077 
00078 if (dir == NULL || sameString(".", dir) || sameString("", dir))
00079     dir = "";
00080 else
00081     {
00082     currentDir = getCurrentDir();
00083     setCurrentDir(dir);
00084     otherDir = TRUE;
00085     }
00086 
00087 if (pattern == NULL)
00088     pattern = *;
00089 if( (hFile = _findfirst( pattern, &fileInfo)) == -1L )
00090     return NULL;
00091 
00092 do
00093     {
00094     if (!sameString(".", fileInfo.name) && !sameString("..", fileInfo.name))
00095         {
00096         name = newSlName(fileInfo.name);
00097         slAddHead(&list, name);
00098         }
00099     }
00100 while( _findnext( hFile, &fileInfo) == 0 );
00101 _findclose( hFile );
00102 if (otherDir)
00103     setCurrentDir(currentDir);
00104 slNameSort(&list);
00105 return list;
00106 }

Generated on Tue Dec 25 18:39:31 2007 for blat by  doxygen 1.5.2