mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-08-01 10:06:59 +03:00
Huge cleanup, I switched to compile with
-Wall -g -O -ansi -pedantic -W -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline - HTMLparser.[ch] HTMLtree.c SAX.c debugXML.c encoding.[ch] encoding.h entities.c error.c list.[ch] nanoftp.c nanohttp.c parser.[ch] parserInternals.[ch] testHTML.c testSAX.c testURI.c testXPath.c tree.[ch] uri.c valid.[ch] xinclude.c xmlIO.[ch] xmllint.c xmlmemory.c xpath.c xpathInternals.h xpointer.[ch] example/gjobread.c: Cleanup, staticfied a number of non-exported functions, detected and cleaned up a dozen of problem found this way, avoided a lot of public function name/typedef/system names clashes - doc/xml.html: updated - configure.in: switched private flags to the really pedantic ones. Daniel
This commit is contained in:
193
xmlIO.c
193
xmlIO.c
@ -118,6 +118,18 @@ xmlOutputCallback xmlOutputCallbackTable[MAX_OUTPUT_CALLBACK];
|
||||
int xmlOutputCallbackNr = 0;
|
||||
int xmlOutputCallbackInitialized = 0;
|
||||
|
||||
/************************************************************************
|
||||
* *
|
||||
* When running GCC in vaacum cleaner mode *
|
||||
* *
|
||||
************************************************************************/
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define UNUSED __attribute__((__unused__))
|
||||
#else
|
||||
#define UNUSED
|
||||
#endif
|
||||
|
||||
/************************************************************************
|
||||
* *
|
||||
* Standard I/O for file accesses *
|
||||
@ -159,94 +171,11 @@ xmlCheckFilename (const char *path)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
xmlNop(void) {
|
||||
return(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlFdMatch:
|
||||
* @filename: the URI for matching
|
||||
*
|
||||
* input from file descriptor
|
||||
*
|
||||
* Returns 1 if matches, 0 otherwise
|
||||
*/
|
||||
int
|
||||
xmlFdMatch (const char *filename) {
|
||||
return(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlFdOpen:
|
||||
* @filename: the URI for matching
|
||||
*
|
||||
* input from file descriptor, supports compressed input
|
||||
* if @filename is "-" then the standard input is used
|
||||
*
|
||||
* Returns an I/O context or NULL in case of error
|
||||
*/
|
||||
void *
|
||||
xmlFdOpen (const char *filename) {
|
||||
const char *path = NULL;
|
||||
int fd;
|
||||
|
||||
if (!strcmp(filename, "-")) {
|
||||
fd = 0;
|
||||
return((void *) fd);
|
||||
}
|
||||
|
||||
if (!strncmp(filename, "file://localhost", 16))
|
||||
path = &filename[16];
|
||||
else if (!strncmp(filename, "file:///", 8))
|
||||
path = &filename[8];
|
||||
else if (filename[0] == '/')
|
||||
path = filename;
|
||||
if (path == NULL)
|
||||
return(NULL);
|
||||
|
||||
#ifdef WIN32
|
||||
fd = _open (path, O_RDONLY | _O_BINARY);
|
||||
#else
|
||||
fd = open (path, O_RDONLY);
|
||||
#endif
|
||||
|
||||
return((void *) fd);
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlFdOpenW:
|
||||
* @filename: the URI for matching
|
||||
*
|
||||
* input from file descriptor,
|
||||
* if @filename is "-" then the standard output is used
|
||||
*
|
||||
* Returns an I/O context or NULL in case of error
|
||||
*/
|
||||
void *
|
||||
xmlFdOpenW (const char *filename) {
|
||||
const char *path = NULL;
|
||||
int fd;
|
||||
|
||||
if (!strcmp(filename, "-")) {
|
||||
fd = 1;
|
||||
return((void *) fd);
|
||||
}
|
||||
|
||||
if (!strncmp(filename, "file://localhost", 16))
|
||||
path = &filename[16];
|
||||
else if (!strncmp(filename, "file:///", 8))
|
||||
path = &filename[8];
|
||||
else if (filename[0] == '/')
|
||||
path = filename;
|
||||
if (path == NULL)
|
||||
return(NULL);
|
||||
|
||||
fd = open (path, O_WRONLY);
|
||||
|
||||
return((void *) fd);
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlFdRead:
|
||||
* @context: the I/O context
|
||||
@ -257,7 +186,7 @@ xmlFdOpenW (const char *filename) {
|
||||
*
|
||||
* Returns the number of bytes written
|
||||
*/
|
||||
int
|
||||
static int
|
||||
xmlFdRead (void * context, char * buffer, int len) {
|
||||
return(read((int) context, &buffer[0], len));
|
||||
}
|
||||
@ -272,7 +201,7 @@ xmlFdRead (void * context, char * buffer, int len) {
|
||||
*
|
||||
* Returns the number of bytes written
|
||||
*/
|
||||
int
|
||||
static int
|
||||
xmlFdWrite (void * context, const char * buffer, int len) {
|
||||
return(write((int) context, &buffer[0], len));
|
||||
}
|
||||
@ -283,7 +212,7 @@ xmlFdWrite (void * context, const char * buffer, int len) {
|
||||
*
|
||||
* Close an I/O channel
|
||||
*/
|
||||
void
|
||||
static void
|
||||
xmlFdClose (void * context) {
|
||||
close((int) context);
|
||||
}
|
||||
@ -296,8 +225,8 @@ xmlFdClose (void * context) {
|
||||
*
|
||||
* Returns 1 if matches, 0 otherwise
|
||||
*/
|
||||
int
|
||||
xmlFileMatch (const char *filename) {
|
||||
static int
|
||||
xmlFileMatch (const char *filename UNUSED) {
|
||||
return(1);
|
||||
}
|
||||
|
||||
@ -310,7 +239,7 @@ xmlFileMatch (const char *filename) {
|
||||
*
|
||||
* Returns an I/O context or NULL in case of error
|
||||
*/
|
||||
void *
|
||||
static void *
|
||||
xmlFileOpen (const char *filename) {
|
||||
const char *path = NULL;
|
||||
FILE *fd;
|
||||
@ -349,7 +278,7 @@ xmlFileOpen (const char *filename) {
|
||||
*
|
||||
* Returns an I/O context or NULL in case of error
|
||||
*/
|
||||
void *
|
||||
static void *
|
||||
xmlFileOpenW (const char *filename) {
|
||||
const char *path = NULL;
|
||||
FILE *fd;
|
||||
@ -383,7 +312,7 @@ xmlFileOpenW (const char *filename) {
|
||||
*
|
||||
* Returns the number of bytes written
|
||||
*/
|
||||
int
|
||||
static int
|
||||
xmlFileRead (void * context, char * buffer, int len) {
|
||||
return(fread(&buffer[0], 1, len, (FILE *) context));
|
||||
}
|
||||
@ -398,7 +327,7 @@ xmlFileRead (void * context, char * buffer, int len) {
|
||||
*
|
||||
* Returns the number of bytes written
|
||||
*/
|
||||
int
|
||||
static int
|
||||
xmlFileWrite (void * context, const char * buffer, int len) {
|
||||
return(fwrite(&buffer[0], 1, len, (FILE *) context));
|
||||
}
|
||||
@ -409,7 +338,7 @@ xmlFileWrite (void * context, const char * buffer, int len) {
|
||||
*
|
||||
* Close an I/O channel
|
||||
*/
|
||||
void
|
||||
static void
|
||||
xmlFileClose (void * context) {
|
||||
fclose((FILE *) context);
|
||||
}
|
||||
@ -420,7 +349,7 @@ xmlFileClose (void * context) {
|
||||
*
|
||||
* Flush an I/O channel
|
||||
*/
|
||||
void
|
||||
static void
|
||||
xmlFileFlush (void * context) {
|
||||
fflush((FILE *) context);
|
||||
}
|
||||
@ -439,8 +368,8 @@ xmlFileFlush (void * context) {
|
||||
*
|
||||
* Returns 1 if matches, 0 otherwise
|
||||
*/
|
||||
int
|
||||
xmlGzfileMatch (const char *filename) {
|
||||
static int
|
||||
xmlGzfileMatch (const char *filename UNUSED) {
|
||||
return(1);
|
||||
}
|
||||
|
||||
@ -453,7 +382,7 @@ xmlGzfileMatch (const char *filename) {
|
||||
*
|
||||
* Returns an I/O context or NULL in case of error
|
||||
*/
|
||||
void *
|
||||
static void *
|
||||
xmlGzfileOpen (const char *filename) {
|
||||
const char *path = NULL;
|
||||
gzFile fd;
|
||||
@ -489,7 +418,7 @@ xmlGzfileOpen (const char *filename) {
|
||||
*
|
||||
* Returns an I/O context or NULL in case of error
|
||||
*/
|
||||
void *
|
||||
static void *
|
||||
xmlGzfileOpenW (const char *filename, int compression) {
|
||||
const char *path = NULL;
|
||||
char mode[15];
|
||||
@ -525,7 +454,7 @@ xmlGzfileOpenW (const char *filename, int compression) {
|
||||
*
|
||||
* Returns the number of bytes written
|
||||
*/
|
||||
int
|
||||
static int
|
||||
xmlGzfileRead (void * context, char * buffer, int len) {
|
||||
return(gzread((gzFile) context, &buffer[0], len));
|
||||
}
|
||||
@ -540,7 +469,7 @@ xmlGzfileRead (void * context, char * buffer, int len) {
|
||||
*
|
||||
* Returns the number of bytes written
|
||||
*/
|
||||
int
|
||||
static int
|
||||
xmlGzfileWrite (void * context, const char * buffer, int len) {
|
||||
return(gzwrite((gzFile) context, (char *) &buffer[0], len));
|
||||
}
|
||||
@ -551,7 +480,7 @@ xmlGzfileWrite (void * context, const char * buffer, int len) {
|
||||
*
|
||||
* Close a compressed I/O channel
|
||||
*/
|
||||
void
|
||||
static void
|
||||
xmlGzfileClose (void * context) {
|
||||
gzclose((gzFile) context);
|
||||
}
|
||||
@ -571,7 +500,7 @@ xmlGzfileClose (void * context) {
|
||||
*
|
||||
* Returns 1 if matches, 0 otherwise
|
||||
*/
|
||||
int
|
||||
static int
|
||||
xmlIOHTTPMatch (const char *filename) {
|
||||
if (!strncmp(filename, "http://", 7))
|
||||
return(1);
|
||||
@ -586,7 +515,7 @@ xmlIOHTTPMatch (const char *filename) {
|
||||
*
|
||||
* Returns an I/O context or NULL in case of error
|
||||
*/
|
||||
void *
|
||||
static void *
|
||||
xmlIOHTTPOpen (const char *filename) {
|
||||
return(xmlNanoHTTPOpen(filename, NULL));
|
||||
}
|
||||
@ -601,7 +530,7 @@ xmlIOHTTPOpen (const char *filename) {
|
||||
*
|
||||
* Returns the number of bytes written
|
||||
*/
|
||||
int
|
||||
static int
|
||||
xmlIOHTTPRead(void * context, char * buffer, int len) {
|
||||
return(xmlNanoHTTPRead(context, &buffer[0], len));
|
||||
}
|
||||
@ -612,7 +541,7 @@ xmlIOHTTPRead(void * context, char * buffer, int len) {
|
||||
*
|
||||
* Close an HTTP I/O channel
|
||||
*/
|
||||
void
|
||||
static void
|
||||
xmlIOHTTPClose (void * context) {
|
||||
xmlNanoHTTPClose(context);
|
||||
}
|
||||
@ -632,7 +561,7 @@ xmlIOHTTPClose (void * context) {
|
||||
*
|
||||
* Returns 1 if matches, 0 otherwise
|
||||
*/
|
||||
int
|
||||
static int
|
||||
xmlIOFTPMatch (const char *filename) {
|
||||
if (!strncmp(filename, "ftp://", 6))
|
||||
return(1);
|
||||
@ -647,7 +576,7 @@ xmlIOFTPMatch (const char *filename) {
|
||||
*
|
||||
* Returns an I/O context or NULL in case of error
|
||||
*/
|
||||
void *
|
||||
static void *
|
||||
xmlIOFTPOpen (const char *filename) {
|
||||
return(xmlNanoFTPOpen(filename));
|
||||
}
|
||||
@ -662,7 +591,7 @@ xmlIOFTPOpen (const char *filename) {
|
||||
*
|
||||
* Returns the number of bytes written
|
||||
*/
|
||||
int
|
||||
static int
|
||||
xmlIOFTPRead(void * context, char * buffer, int len) {
|
||||
return(xmlNanoFTPRead(context, &buffer[0], len));
|
||||
}
|
||||
@ -673,7 +602,7 @@ xmlIOFTPRead(void * context, char * buffer, int len) {
|
||||
*
|
||||
* Close an FTP I/O channel
|
||||
*/
|
||||
void
|
||||
static void
|
||||
xmlIOFTPClose (void * context) {
|
||||
xmlNanoFTPClose(context);
|
||||
}
|
||||
@ -682,51 +611,51 @@ xmlIOFTPClose (void * context) {
|
||||
|
||||
/**
|
||||
* xmlRegisterInputCallbacks:
|
||||
* @match: the xmlInputMatchCallback
|
||||
* @open: the xmlInputOpenCallback
|
||||
* @read: the xmlInputReadCallback
|
||||
* @close: the xmlInputCloseCallback
|
||||
* @matchFunc: the xmlInputMatchCallback
|
||||
* @openFunc: the xmlInputOpenCallback
|
||||
* @readFunc: the xmlInputReadCallback
|
||||
* @closeFunc: the xmlInputCloseCallback
|
||||
*
|
||||
* Register a new set of I/O callback for handling parser input.
|
||||
*
|
||||
* Returns the registered handler number or -1 in case of error
|
||||
*/
|
||||
int
|
||||
xmlRegisterInputCallbacks(xmlInputMatchCallback match,
|
||||
xmlInputOpenCallback open, xmlInputReadCallback read,
|
||||
xmlInputCloseCallback close) {
|
||||
xmlRegisterInputCallbacks(xmlInputMatchCallback matchFunc,
|
||||
xmlInputOpenCallback openFunc, xmlInputReadCallback readFunc,
|
||||
xmlInputCloseCallback closeFunc) {
|
||||
if (xmlInputCallbackNr >= MAX_INPUT_CALLBACK) {
|
||||
return(-1);
|
||||
}
|
||||
xmlInputCallbackTable[xmlInputCallbackNr].matchcallback = match;
|
||||
xmlInputCallbackTable[xmlInputCallbackNr].opencallback = open;
|
||||
xmlInputCallbackTable[xmlInputCallbackNr].readcallback = read;
|
||||
xmlInputCallbackTable[xmlInputCallbackNr].closecallback = close;
|
||||
xmlInputCallbackTable[xmlInputCallbackNr].matchcallback = matchFunc;
|
||||
xmlInputCallbackTable[xmlInputCallbackNr].opencallback = openFunc;
|
||||
xmlInputCallbackTable[xmlInputCallbackNr].readcallback = readFunc;
|
||||
xmlInputCallbackTable[xmlInputCallbackNr].closecallback = closeFunc;
|
||||
return(xmlInputCallbackNr++);
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlRegisterOutputCallbacks:
|
||||
* @match: the xmlOutputMatchCallback
|
||||
* @open: the xmlOutputOpenCallback
|
||||
* @write: the xmlOutputWriteCallback
|
||||
* @close: the xmlOutputCloseCallback
|
||||
* @matchFunc: the xmlOutputMatchCallback
|
||||
* @openFunc: the xmlOutputOpenCallback
|
||||
* @writeFunc: the xmlOutputWriteCallback
|
||||
* @closeFunc: the xmlOutputCloseCallback
|
||||
*
|
||||
* Register a new set of I/O callback for handling output.
|
||||
*
|
||||
* Returns the registered handler number or -1 in case of error
|
||||
*/
|
||||
int
|
||||
xmlRegisterOutputCallbacks(xmlOutputMatchCallback match,
|
||||
xmlOutputOpenCallback open, xmlOutputWriteCallback write,
|
||||
xmlOutputCloseCallback close) {
|
||||
xmlRegisterOutputCallbacks(xmlOutputMatchCallback matchFunc,
|
||||
xmlOutputOpenCallback openFunc, xmlOutputWriteCallback writeFunc,
|
||||
xmlOutputCloseCallback closeFunc) {
|
||||
if (xmlOutputCallbackNr >= MAX_INPUT_CALLBACK) {
|
||||
return(-1);
|
||||
}
|
||||
xmlOutputCallbackTable[xmlOutputCallbackNr].matchcallback = match;
|
||||
xmlOutputCallbackTable[xmlOutputCallbackNr].opencallback = open;
|
||||
xmlOutputCallbackTable[xmlOutputCallbackNr].writecallback = write;
|
||||
xmlOutputCallbackTable[xmlOutputCallbackNr].closecallback = close;
|
||||
xmlOutputCallbackTable[xmlOutputCallbackNr].matchcallback = matchFunc;
|
||||
xmlOutputCallbackTable[xmlOutputCallbackNr].opencallback = openFunc;
|
||||
xmlOutputCallbackTable[xmlOutputCallbackNr].writecallback = writeFunc;
|
||||
xmlOutputCallbackTable[xmlOutputCallbackNr].closecallback = closeFunc;
|
||||
return(xmlOutputCallbackNr++);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user