From 3992a5169c0b3805c38729c3856c41b1b2527765 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 15 Apr 2000 02:52:51 +0000 Subject: [PATCH] use open() not fopen() on codepage files. in general we need to get rid of all uses of fopen(). The hard one will be the debug code and dbf. --- source/lib/charset.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/source/lib/charset.c b/source/lib/charset.c index 6e5a4b48cba..3d081246fd3 100644 --- a/source/lib/charset.c +++ b/source/lib/charset.c @@ -188,7 +188,7 @@ static codepage_p load_client_codepage( int client_codepage ) { pstring codepage_file_name; unsigned char buf[8]; - FILE *fp = NULL; + int fd = -1; SMB_OFF_T size; codepage_p cp_p = NULL; SMB_STRUCT_STAT st; @@ -235,14 +235,14 @@ code page file (size=%d).\n", codepage_file_name, (int)size)); is held in little endian format. */ - if((fp = sys_fopen( codepage_file_name, "r")) == NULL) + if((fd = open(codepage_file_name, O_RDONLY)) == -1) { DEBUG(0,("load_client_codepage: cannot open file %s. Error was %s\n", codepage_file_name, strerror(errno))); return NULL; } - if(fread( buf, 1, CODEPAGE_HEADER_SIZE, fp)!=CODEPAGE_HEADER_SIZE) + if (read(fd, buf, CODEPAGE_HEADER_SIZE)!=CODEPAGE_HEADER_SIZE) { DEBUG(0,("load_client_codepage: cannot read header from file %s. Error was %s\n", codepage_file_name, strerror(errno))); @@ -295,7 +295,7 @@ multiple of 4.\n", codepage_file_name)); goto clean_and_exit; } - if(fread( (char *)cp_p, 1, size, fp)!=size) + if(read(fd, (char *)cp_p, size)!=size) { DEBUG(0,("load_client_codepage: read fail on file %s. Error was %s.\n", codepage_file_name, strerror(errno))); @@ -305,15 +305,15 @@ multiple of 4.\n", codepage_file_name)); /* Ensure array is correctly terminated. */ memset(((char *)cp_p) + size, '\0', 4); - fclose(fp); + close(fd); return cp_p; clean_and_exit: /* pseudo destructor :-) */ - if(fp != NULL) - fclose(fp); + if(fd != -1) + close(fd); if(cp_p) free((char *)cp_p); return NULL;