Initial source commit
This commit is contained in:
commit
f1384c11ee
335 changed files with 52715 additions and 0 deletions
53
minorGems/io/file/win32/DirectoryWin32.cpp
Normal file
53
minorGems/io/file/win32/DirectoryWin32.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Modification History
|
||||
*
|
||||
* 2003-January-23 Jason Rohrer
|
||||
* Created.
|
||||
*
|
||||
* 2003-November-10 Jason Rohrer
|
||||
* Added makeDirectory function.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "minorGems/io/file/Directory.h"
|
||||
|
||||
|
||||
|
||||
#include <direct.h>
|
||||
|
||||
|
||||
|
||||
char Directory::removeDirectory( File *inFile ) {
|
||||
char *fileName = inFile->getFullFileName();
|
||||
|
||||
int result = _rmdir( fileName );
|
||||
|
||||
delete [] fileName;
|
||||
|
||||
if( result == 0 ) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
char Directory::makeDirectory( File *inFile ) {
|
||||
char *stringName = inFile->getFullFileName();
|
||||
|
||||
int result = mkdir( stringName );
|
||||
|
||||
delete [] stringName;
|
||||
|
||||
if( 0 == result ) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
95
minorGems/io/file/win32/PathWin32.cpp
Normal file
95
minorGems/io/file/win32/PathWin32.cpp
Normal file
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* Modification History
|
||||
*
|
||||
* 2001-February-12 Jason Rohrer
|
||||
* Created.
|
||||
*
|
||||
* 2001-March-4 Jason Rohrer
|
||||
* Fixed delimeter constants.
|
||||
*
|
||||
* 2001-August-1 Jason Rohrer
|
||||
* Added missing length return value.
|
||||
*
|
||||
* 2003-June-2 Jason Rohrer
|
||||
* Added support for new path checking functions.
|
||||
*
|
||||
* 2010-May-14 Jason Rohrer
|
||||
* String parameters as const to fix warnings.
|
||||
*/
|
||||
|
||||
#include "minorGems/io/file/Path.h"
|
||||
#include "minorGems/util/stringUtils.h"
|
||||
|
||||
|
||||
/*
|
||||
* Windows-specific path implementation.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
char Path::getDelimeter() {
|
||||
return '\\';
|
||||
}
|
||||
|
||||
|
||||
|
||||
char *Path::getAbsoluteRoot( int *outLength) {
|
||||
// C:\ is the only root we can generically return
|
||||
|
||||
char *returnString = new char[3];
|
||||
|
||||
returnString[0] = 'C';
|
||||
returnString[1] = ':';
|
||||
returnString[2] = '\\';
|
||||
|
||||
*outLength = 3;
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char Path::isAbsolute( const char *inPathString ) {
|
||||
// ignore first character, which will be drive letter
|
||||
if( inPathString[1] == ':' && inPathString[2] == '\\' ) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
char *Path::extractRoot( const char *inPathString ) {
|
||||
if( isAbsolute( inPathString ) ){
|
||||
// copy path, then trim to only three characters
|
||||
|
||||
char *pathCopy = stringDuplicate( inPathString );
|
||||
pathCopy[ 3 ] = '\0';
|
||||
|
||||
char *trimmedCopy = stringDuplicate( pathCopy );
|
||||
delete [] pathCopy;
|
||||
|
||||
return trimmedCopy;
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
char Path::isRoot( const char *inPathString ) {
|
||||
// must be of form "c:\"
|
||||
if( strlen( inPathString ) == 3 &&
|
||||
inPathString[1] == ':' &&
|
||||
inPathString[2] == '\\' ) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
159
minorGems/io/file/win32/dirent.cpp
Normal file
159
minorGems/io/file/win32/dirent.cpp
Normal file
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
* Modification History
|
||||
*
|
||||
* 2002-April-7 Jason Rohrer
|
||||
* Added a mkdir wrapper for CodeWarrior.
|
||||
*
|
||||
* 2002-April-11 Jason Rohrer
|
||||
* Changed type of mode parameter to work with Visual C++.
|
||||
* Added missing include.
|
||||
*
|
||||
* 2002-July-22 Jason Rohrer
|
||||
* Commented out mkdir replacement function to work with new MSL.
|
||||
*
|
||||
* 2002-October-13 Jason Rohrer
|
||||
* Re-added mkdir wrapper function, since both CW4 and VC++ need it.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
Implementation of POSIX directory browsing functions and types for Win32.
|
||||
|
||||
Kevlin Henney (mailto:kevlin@acm.org), March 1997.
|
||||
|
||||
Copyright Kevlin Henney, 1997. All rights reserved.
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose is hereby granted without fee, provided
|
||||
that this copyright and permissions notice appear in all copies and
|
||||
derivatives, and that no charge may be made for the software and its
|
||||
documentation except to cover cost of distribution.
|
||||
|
||||
This software is supplied "as is" without express or implied warranty.
|
||||
|
||||
But that said, if there are any problems please get in touch.
|
||||
|
||||
*/
|
||||
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <io.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <direct.h>
|
||||
|
||||
|
||||
struct DIR
|
||||
{
|
||||
long handle; /* -1 for failed rewind */
|
||||
struct _finddata_t info;
|
||||
struct dirent result; /* d_name null iff first time */
|
||||
char *name; /* NTBS */
|
||||
};
|
||||
|
||||
DIR *opendir(const char *name)
|
||||
{
|
||||
DIR *dir = 0;
|
||||
|
||||
if(name && name[0])
|
||||
{
|
||||
size_t base_length = strlen(name);
|
||||
const char *all = /* the root directory is a special case... */
|
||||
strchr("/\\", name[base_length - 1]) ? "*" : "/*";
|
||||
|
||||
if((dir = (DIR *) malloc(sizeof *dir)) != 0 &&
|
||||
(dir->name = (char *) malloc(base_length + strlen(all) + 1)) != 0)
|
||||
{
|
||||
strcat(strcpy(dir->name, name), all);
|
||||
|
||||
if((dir->handle = _findfirst(dir->name, &dir->info)) != -1)
|
||||
{
|
||||
dir->result.d_name = 0;
|
||||
}
|
||||
else /* rollback */
|
||||
{
|
||||
free(dir->name);
|
||||
free(dir);
|
||||
dir = 0;
|
||||
}
|
||||
}
|
||||
else /* rollback */
|
||||
{
|
||||
free(dir);
|
||||
dir = 0;
|
||||
errno = ENOMEM;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errno = EINVAL;
|
||||
}
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
int closedir(DIR *dir)
|
||||
{
|
||||
int result = -1;
|
||||
|
||||
if(dir)
|
||||
{
|
||||
if(dir->handle != -1)
|
||||
{
|
||||
result = _findclose(dir->handle);
|
||||
}
|
||||
|
||||
free(dir->name);
|
||||
free(dir);
|
||||
}
|
||||
|
||||
if(result == -1) /* map all errors to EBADF */
|
||||
{
|
||||
errno = EBADF;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
struct dirent *readdir(DIR *dir)
|
||||
{
|
||||
struct dirent *result = 0;
|
||||
|
||||
if(dir && dir->handle != -1)
|
||||
{
|
||||
if(!dir->result.d_name || _findnext(dir->handle, &dir->info) != -1)
|
||||
{
|
||||
result = &dir->result;
|
||||
result->d_name = dir->info.name;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
errno = EBADF;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void rewinddir(DIR *dir)
|
||||
{
|
||||
if(dir && dir->handle != -1)
|
||||
{
|
||||
_findclose(dir->handle);
|
||||
dir->handle = _findfirst(dir->name, &dir->info);
|
||||
dir->result.d_name = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
errno = EBADF;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int mkdir( const char *pathname, unsigned int mode ) {
|
||||
return mkdir( pathname );
|
||||
}
|
77
minorGems/io/file/win32/dirent.h
Normal file
77
minorGems/io/file/win32/dirent.h
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Modification History
|
||||
*
|
||||
* 2002-April-7 Jason Rohrer
|
||||
* Added a mkdir wrapper for CodeWarrior.
|
||||
*
|
||||
* 2002-April-11 Jason Rohrer
|
||||
* Changed type of mode parameter to work with Visual C++.
|
||||
* Added missing macros.
|
||||
*
|
||||
* 2002-July-22 Jason Rohrer
|
||||
* Commented out mkdir replacement function to work with new MSL.
|
||||
*
|
||||
* 2002-October-13 Jason Rohrer
|
||||
* Re-added mkdir wrapper function, since both CW4 and VC++ need it.
|
||||
*/
|
||||
|
||||
#include "minorGems/common.h"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
Declaration of POSIX directory browsing functions and types for Win32.
|
||||
|
||||
Kevlin Henney (mailto:kevlin@acm.org), March 1997.
|
||||
|
||||
Copyright Kevlin Henney, 1997. All rights reserved.
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose is hereby granted without fee, provided
|
||||
that this copyright and permissions notice appear in all copies and
|
||||
derivatives, and that no charge may be made for the software and its
|
||||
documentation except to cover cost of distribution.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef DIRENT_INCLUDED
|
||||
#define DIRENT_INCLUDED
|
||||
|
||||
typedef struct DIR DIR;
|
||||
|
||||
struct dirent
|
||||
{
|
||||
char *d_name;
|
||||
};
|
||||
|
||||
DIR *opendir(const char *);
|
||||
int closedir(DIR *);
|
||||
struct dirent *readdir(DIR *);
|
||||
void rewinddir(DIR *);
|
||||
|
||||
|
||||
|
||||
#include <sys/stat.h>
|
||||
/**
|
||||
* The Metrowerks Standard Library seems
|
||||
* to have only a 1-parameter mkdir command in sys/stat.h.
|
||||
*/
|
||||
int mkdir( const char *pathname, unsigned int mode );
|
||||
|
||||
|
||||
// make sure our needed macros are defined
|
||||
// S_IFMT and S_IFDIR seem to be defined everywhere
|
||||
|
||||
#ifndef __S_ISTYPE
|
||||
#define __S_ISTYPE(mode, mask) (((mode) & S_IFMT) == (mask))
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef S_ISDIR
|
||||
#define S_ISDIR(mode) __S_ISTYPE((mode), S_IFDIR)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue