[NeoStats-Devel] [Commits] r2389 - trunk/src

[email protected]
Newsgroups gmane.comp.neostats.devel
Message-ID <[email protected]>
Author: Mark
Date: Tue Mar 22 07:46:11 2005
New Revision: 2389

Added:
   trunk/src/osfile.c
Modified:
   trunk/src/Makefile.am
   trunk/src/Makefile.in
   trunk/src/neostats.vcproj
   trunk/src/oscalls.c
Log:
os calls updates

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Tue Mar 22 07:46:11 2005
@@ -8,7 +8,7 @@
 		ns_help.c servers.c services.c signals.c sock.c support.c \
 		timer.c transfer.c users.c modes.c ctcp.c dcc.c nsmemory.c \
 		base64.c numerics.c settings.c botinfo.c \
-		oscalls.c ossocket.c 
+		oscalls.c ossocket.c osfile.c 
 AM_CFLAGS = 	-I$(top_srcdir)/lib/adns \
 		@PCRE_CFLAGS@ @CURL_CFLAGS@ -DNEOSTATSCORE \
 		-I$(top_srcdir)/lib/event

Modified: trunk/src/Makefile.in
==============================================================================
--- trunk/src/Makefile.in	(original)
+++ trunk/src/Makefile.in	Tue Mar 22 07:46:11 2005
@@ -70,7 +70,7 @@
 	modes.$(OBJEXT) ctcp.$(OBJEXT) dcc.$(OBJEXT) \
 	nsmemory.$(OBJEXT) base64.$(OBJEXT) numerics.$(OBJEXT) \
 	settings.$(OBJEXT) botinfo.$(OBJEXT) oscalls.$(OBJEXT) \
-	ossocket.$(OBJEXT)
+	ossocket.$(OBJEXT) osfile.$(OBJEXT)
 neostats_OBJECTS = $(am_neostats_OBJECTS)
 neostats_DEPENDENCIES = $(top_srcdir)/lib/adns/libadns.la \
 	$(top_srcdir)/lib/event/libevent.a
@@ -227,7 +227,7 @@
 		ns_help.c servers.c services.c signals.c sock.c support.c \
 		timer.c transfer.c users.c modes.c ctcp.c dcc.c nsmemory.c \
 		base64.c numerics.c settings.c botinfo.c \
-		oscalls.c ossocket.c 
+		oscalls.c ossocket.c osfile.c 
 
 AM_CFLAGS = -I$(top_srcdir)/lib/adns \
 		@PCRE_CFLAGS@ @CURL_CFLAGS@ -DNEOSTATSCORE \
@@ -331,6 +331,7 @@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nsmemory.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/numerics.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/oscalls.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/osfile.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ossocket.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/servers.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/services.Po@am__quote@

Modified: trunk/src/neostats.vcproj
==============================================================================
--- trunk/src/neostats.vcproj	(original)
+++ trunk/src/neostats.vcproj	Tue Mar 22 07:46:11 2005
@@ -210,6 +210,9 @@
 				RelativePath=".\oscalls.c">
 			</File>
 			<File
+				RelativePath=".\osfile.c">
+			</File>
+			<File
 				RelativePath=".\ossocket.c">
 			</File>
 			<File

Modified: trunk/src/oscalls.c
==============================================================================
--- trunk/src/oscalls.c	(original)
+++ trunk/src/oscalls.c	Tue Mar 22 07:46:11 2005
@@ -29,354 +29,6 @@
  */
 
 #include "neostats.h"
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h> 
-#endif
-
-int os_errno;
-static char tempbuf[BUFSIZE*2];
-
-/*
- *  Wrapper function for mkdir
- */
-
-int os_mkdir( const char *filename, mode_t mode )
-{
-	int retval;
-
-#ifdef WIN32
-	retval = mkdir( filename );
-#else
-	retval = mkdir( filename, mode );
-#endif
-	os_errno = errno;
-	return retval;
-}
-
-/*
- *  Wrapper function for check_create_dir
- */
-
-int os_check_create_dir( const char *dirname )
-{
-	struct stat st;
-	int res;
-
-	/* first, make sure the logdir dir exists */
-	res = stat( dirname, &st );
-	if( res != 0 ) {
-		/* hrm, error */
-		if( errno == ENOENT ) {
-			/* ok, it doesn't exist, create it */
-			res = os_mkdir( dirname, 0700 );
-			if( res != 0 ) {
-				/* error */
-				nlog( LOG_CRITICAL, "Couldn't create directory: %s", strerror( errno ) );
-				return NS_FAILURE;
-			}
-			nlog( LOG_NOTICE, "Created directory: %s", dirname );
-		} else {
-			nlog( LOG_CRITICAL, "Stat returned error: %s", strerror( errno ) );
-			return NS_FAILURE;
-		}
-	} else if( !S_ISDIR( st.st_mode ) )	{
-		nlog( LOG_CRITICAL, "%s is not a Directory", dirname );
-		return NS_FAILURE;
-	}
-	return NS_SUCCESS;
-}
-
-/*
- *  Wrapper function for fopen
- */
-
-FILE* os_fopen( const char *filename, const char *filemode )
-{
-	FILE *retval;
-
-	retval = fopen( filename, filemode );
-	os_errno = errno;
-	return retval;
-}
-
-/*
- *  Wrapper function for fclose
- */
-
-int os_fclose( FILE *handle )
-{
-	int retval;
-
-	retval = fclose( handle );
-	os_errno = errno;
-	return retval;
-}
-
-/*
- *  Wrapper function for fseek
- */
-
-int os_fseek( FILE *handle, long offset, int origin )
-{
-	int retval;
-
-	retval = fseek( handle, offset, origin );
-	os_errno = errno;
-	return retval;
-}
-
-/*
- *  Wrapper function for ftell
- */
-
-long os_ftell( FILE *handle )
-{
-	int retval;
-
-	retval = ftell( handle );
-	os_errno = errno;
-	return retval;
-}
-
-/*
- *  Wrapper function for fprintf
- */
-
-int os_fprintf( FILE *handle, char *fmt, ... )
-{
-	int retval;
-	va_list ap;
-
-	va_start( ap, fmt );
-	ircvsnprintf( tempbuf, BUFSIZE*2, fmt, ap );
-	va_end( ap );
-	retval = fprintf( handle, "%s", tempbuf );	
-	os_errno = errno;
-	return retval;
-}
-
-/*
- *  Wrapper function for fputs
- */
-
-int os_fputs( const char *string, FILE *handle )
-{
-	int retval;
-
-	retval = fputs( string, handle );	
-	os_errno = errno;
-	return retval;
-}
-
-/*
- *  Wrapper function for fread
- */
-
-int os_fread( void *buffer, size_t size, size_t count, FILE* handle )
-{
-	int retval;
-
-	retval = fread( buffer, size, count, handle );
-	os_errno = errno;
-	return retval;
-}
-
-/*
- *  Wrapper function for fgets
- */
-
-char *os_fgets( char *string, int n, FILE* handle )
-{
-	char *retval;
-
-	retval = fgets( string, n, handle );
-	os_errno = errno;
-	return retval;
-}
-
-/*
- *  Wrapper function for fwrite
- */
-
-int os_fwrite( const void *buffer, size_t size, size_t count, FILE* handle )
-{
-	int retval;
-
-	retval = fwrite( buffer, size, count, handle );
-	os_errno = errno;
-	return retval;
-}
-
-/*
- *  Wrapper function for fflush
- */
-
-int os_fflush( FILE *handle )
-{
-	int retval;
-
-	retval = fflush( handle );
-	os_errno = errno;
-	return retval;
-}
-
-/*
- *  Wrapper function for rename
- */
-
-int os_rename( const char* oldname, const char* newname )
-{
-	int retval;
-    
-	/*  WIN32 does not allow rename if the file exists 
-	 *  Behaviour is undefined on various systems so 
-	 *  remove on all platforms
-	 */
-	remove( newname );
-	retval = rename( oldname, newname );
-	os_errno = errno;
-	return retval;
-}
-
-/*
- *  Wrapper function for stat
- */
-
-int os_stat( const char *path, struct stat *buffer )
-{
-	int retval;
-
-	retval = stat( path, buffer );
-	os_errno = errno;
-	return retval;
-}
-
-/*
- *  Wrapper function for access
- */
-
-int os_access( const char *path, int mode )
-{
-	int retval;
-
-	retval = access( path, mode );
-	os_errno = errno;
-	return retval;
-}
-
-/*
- *  Wrapper function for write
- */
-
-int os_write( int fd, const void *buffer, unsigned int count )
-{
-	int retval;
-
-	retval = write( fd, buffer, count );
-	os_errno = errno;
-	return retval;
-}
-
-/*
- *  Wrapper function for close
- */
-
-int os_close( int fd )
-{
-	int retval;
-
-	retval = close( fd );
-	os_errno = errno;
-	return retval;
-}
-
-/*
- *  Wrapper function for mkstemp
- */
-
-int os_mkstemp( char *ftemplate )
-{
-#ifdef WIN32
-	int retval;
-	char *name;
-
-	name = mktemp( ftemplate );
-	if( name )
-	{
-		retval = open( name, _O_CREAT, _S_IREAD | _S_IWRITE );
-		os_errno = errno;
-		printf( strerror( errno ) );
-		return retval;
-	}
-	return -1;
-#else
-	return mkstemp( ftemplate );
-#endif
-}
-
-/*
- *  Wrapper function for write_temp_file
- */
-
-int os_write_temp_file( char *ftemplate, const void *buffer, unsigned int count )
-{
-#ifdef WIN32
-	char *name;
-
-	name = mktemp( ftemplate );
-	if( name )
-	{
-		FILE* file;
-		file = fopen( name, "w" );
-		if( file )
-		{
-			fwrite( buffer, count, 1, file );
-			fclose( file );
-			return 0;
-		}
-	}
-	return -1;
-#else
-	int i;
-
-	i = mkstemp( ftemplate );
-	write(i, buffer, count );
-	close(i);
-	return 0;
-#endif
-}
-
-
-/*
- *  Wrapper function for strerror
- */
-
-char *os_strerror( void )
-{
-	return strerror( errno );
-}
-
-/*
- *  Wrapper function for file_get_size
- */
-
-int os_file_get_size( const char* filename )
-{
-	struct stat st;
-	int res;
-
-	res = stat( filename, &st );
-	if( res != 0 ) {
-		if( errno == ENOENT ) {
-			nlog( LOG_CRITICAL, "No such file: %s", filename );
-			return -1;
-		} else {
-			nlog( LOG_CRITICAL, "File error: %s", os_strerror() );
-			return -1;
-		}
-	}
-	return st.st_size;
-}
 
 /*
  *  Wrapper function for strftime

Added: trunk/src/osfile.c
==============================================================================
--- (empty file)
+++ trunk/src/osfile.c	Tue Mar 22 07:46:11 2005
@@ -0,0 +1,378 @@
+/* NeoStats - IRC Statistical Services 
+** Copyright (c) 1999-2005 Adam Rutter, Justin Hammond, Mark Hetherington
+** http://www.neostats.net/
+**
+**  This program 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 of the License, or
+**  (at your option) any later version.
+**
+**  This program 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 this program; if not, write to the Free Software
+**  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
+**  USA
+**
+** NeoStats CVS Identification
+** $Id: oscalls.c 2386 2005-03-21 23:26:24Z Mark $
+*/
+
+/* @file Portability wrapper functions
+ */
+
+/*  TODO:
+ *  - port file functions from CRT to Win32 native calls (CreateFile etc)
+ */
+
+#include "neostats.h"
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h> 
+#endif
+
+int os_errno;
+static char tempbuf[BUFSIZE*2];
+
+/*
+ *  Wrapper function for mkdir
+ */
+
+int os_mkdir( const char *filename, mode_t mode )
+{
+	int retval;
+
+#ifdef WIN32
+	retval = mkdir( filename );
+#else
+	retval = mkdir( filename, mode );
+#endif
+	os_errno = errno;
+	return retval;
+}
+
+/*
+ *  Wrapper function for check_create_dir
+ */
+
+int os_check_create_dir( const char *dirname )
+{
+	struct stat st;
+	int res;
+
+	/* first, make sure the logdir dir exists */
+	res = stat( dirname, &st );
+	if( res != 0 ) {
+		/* hrm, error */
+		if( errno == ENOENT ) {
+			/* ok, it doesn't exist, create it */
+			res = os_mkdir( dirname, 0700 );
+			if( res != 0 ) {
+				/* error */
+				nlog( LOG_CRITICAL, "Couldn't create directory: %s", strerror( errno ) );
+				return NS_FAILURE;
+			}
+			nlog( LOG_NOTICE, "Created directory: %s", dirname );
+		} else {
+			nlog( LOG_CRITICAL, "Stat returned error: %s", strerror( errno ) );
+			return NS_FAILURE;
+		}
+	} else if( !S_ISDIR( st.st_mode ) )	{
+		nlog( LOG_CRITICAL, "%s is not a Directory", dirname );
+		return NS_FAILURE;
+	}
+	return NS_SUCCESS;
+}
+
+/*
+ *  Wrapper function for fopen
+ */
+
+FILE* os_fopen( const char *filename, const char *filemode )
+{
+	FILE *retval;
+
+	retval = fopen( filename, filemode );
+	os_errno = errno;
+	return retval;
+}
+
+/*
+ *  Wrapper function for fclose
+ */
+
+int os_fclose( FILE *handle )
+{
+	int retval;
+
+	retval = fclose( handle );
+	os_errno = errno;
+	return retval;
+}
+
+/*
+ *  Wrapper function for fseek
+ */
+
+int os_fseek( FILE *handle, long offset, int origin )
+{
+	int retval;
+
+	retval = fseek( handle, offset, origin );
+	os_errno = errno;
+	return retval;
+}
+
+/*
+ *  Wrapper function for ftell
+ */
+
+long os_ftell( FILE *handle )
+{
+	int retval;
+
+	retval = ftell( handle );
+	os_errno = errno;
+	return retval;
+}
+
+/*
+ *  Wrapper function for fprintf
+ */
+
+int os_fprintf( FILE *handle, char *fmt, ... )
+{
+	int retval;
+	va_list ap;
+
+	va_start( ap, fmt );
+	ircvsnprintf( tempbuf, BUFSIZE*2, fmt, ap );
+	va_end( ap );
+	retval = fprintf( handle, "%s", tempbuf );	
+	os_errno = errno;
+	return retval;
+}
+
+/*
+ *  Wrapper function for fputs
+ */
+
+int os_fputs( const char *string, FILE *handle )
+{
+	int retval;
+
+	retval = fputs( string, handle );	
+	os_errno = errno;
+	return retval;
+}
+
+/*
+ *  Wrapper function for fread
+ */
+
+int os_fread( void *buffer, size_t size, size_t count, FILE* handle )
+{
+	int retval;
+
+	retval = fread( buffer, size, count, handle );
+	os_errno = errno;
+	return retval;
+}
+
+/*
+ *  Wrapper function for fgets
+ */
+
+char *os_fgets( char *string, int n, FILE* handle )
+{
+	char *retval;
+
+	retval = fgets( string, n, handle );
+	os_errno = errno;
+	return retval;
+}
+
+/*
+ *  Wrapper function for fwrite
+ */
+
+int os_fwrite( const void *buffer, size_t size, size_t count, FILE* handle )
+{
+	int retval;
+
+	retval = fwrite( buffer, size, count, handle );
+	os_errno = errno;
+	return retval;
+}
+
+/*
+ *  Wrapper function for fflush
+ */
+
+int os_fflush( FILE *handle )
+{
+	int retval;
+
+	retval = fflush( handle );
+	os_errno = errno;
+	return retval;
+}
+
+/*
+ *  Wrapper function for rename
+ */
+
+int os_rename( const char* oldname, const char* newname )
+{
+	int retval;
+    
+	/*  WIN32 does not allow rename if the file exists 
+	 *  Behaviour is undefined on various systems so 
+	 *  remove on all platforms
+	 */
+	remove( newname );
+	retval = rename( oldname, newname );
+	os_errno = errno;
+	return retval;
+}
+
+/*
+ *  Wrapper function for stat
+ */
+
+int os_stat( const char *path, struct stat *buffer )
+{
+	int retval;
+
+	retval = stat( path, buffer );
+	os_errno = errno;
+	return retval;
+}
+
+/*
+ *  Wrapper function for access
+ */
+
+int os_access( const char *path, int mode )
+{
+	int retval;
+
+	retval = access( path, mode );
+	os_errno = errno;
+	return retval;
+}
+
+/*
+ *  Wrapper function for write
+ */
+
+int os_write( int fd, const void *buffer, unsigned int count )
+{
+	int retval;
+
+	retval = write( fd, buffer, count );
+	os_errno = errno;
+	return retval;
+}
+
+/*
+ *  Wrapper function for close
+ */
+
+int os_close( int fd )
+{
+	int retval;
+
+	retval = close( fd );
+	os_errno = errno;
+	return retval;
+}
+
+/*
+ *  Wrapper function for mkstemp
+ */
+
+int os_mkstemp( char *ftemplate )
+{
+#ifdef WIN32
+	int retval;
+	char *name;
+
+	name = mktemp( ftemplate );
+	if( name )
+	{
+		retval = open( name, _O_CREAT, _S_IREAD | _S_IWRITE );
+		os_errno = errno;
+		printf( strerror( errno ) );
+		return retval;
+	}
+	return -1;
+#else
+	return mkstemp( ftemplate );
+#endif
+}
+
+/*
+ *  Wrapper function for write_temp_file
+ */
+
+int os_write_temp_file( char *ftemplate, const void *buffer, unsigned int count )
+{
+#ifdef WIN32
+	char *name;
+
+	name = mktemp( ftemplate );
+	if( name )
+	{
+		FILE* file;
+		file = fopen( name, "w" );
+		if( file )
+		{
+			fwrite( buffer, count, 1, file );
+			fclose( file );
+			return 0;
+		}
+	}
+	return -1;
+#else
+	int i;
+
+	i = mkstemp( ftemplate );
+	write(i, buffer, count );
+	close(i);
+	return 0;
+#endif
+}
+
+/*
+ *  Wrapper function for strerror
+ */
+
+char *os_strerror( void )
+{
+	return strerror( errno );
+}
+
+/*
+ *  Wrapper function for file_get_size
+ */
+
+int os_file_get_size( const char* filename )
+{
+	struct stat st;
+	int res;
+
+	res = stat( filename, &st );
+	if( res != 0 ) {
+		if( errno == ENOENT ) {
+			nlog( LOG_CRITICAL, "No such file: %s", filename );
+			return -1;
+		} else {
+			nlog( LOG_CRITICAL, "File error: %s", os_strerror() );
+			return -1;
+		}
+	}
+	return st.st_size;
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.