diff options
author | MySQL Team <mysql@php.net> | 2001-01-23 16:48:50 +0000 |
---|---|---|
committer | MySQL Team <mysql@php.net> | 2001-01-23 16:48:50 +0000 |
commit | 800f555b707c696798877c80352ded46289e87c4 (patch) | |
tree | c540242b6e6da4e9b99b46797a26b215abef0a64 /ext/mysql/libmysql/my_open.c | |
parent | d36858681a0d48414702524ebd16f31289b06fa8 (diff) | |
download | php-git-800f555b707c696798877c80352ded46289e87c4.tar.gz |
Upgrade ext/mysql/libmysql to version 3.23.32. One notable bug fix is
that the client can now connect to a server which is using a default
charset other than latin1.
Diffstat (limited to 'ext/mysql/libmysql/my_open.c')
-rw-r--r-- | ext/mysql/libmysql/my_open.c | 92 |
1 files changed, 61 insertions, 31 deletions
diff --git a/ext/mysql/libmysql/my_open.c b/ext/mysql/libmysql/my_open.c index 15b5a047d0..32f90b635e 100644 --- a/ext/mysql/libmysql/my_open.c +++ b/ext/mysql/libmysql/my_open.c @@ -4,8 +4,9 @@ This file is public domain and comes with NO WARRANTY of any kind */ #define USES_TYPES #include "mysys_priv.h" #include "mysys_err.h" +#include <my_dir.h> #include <errno.h> -#if defined(MSDOS) || defined(__WIN__) +#if defined(MSDOS) || defined(__WIN__) || defined(__EMX__) #include <share.h> #endif @@ -20,40 +21,20 @@ File my_open(const char *FileName, int Flags, myf MyFlags) DBUG_ENTER("my_open"); DBUG_PRINT("my",("Name: '%s' Flags: %d MyFlags: %d", FileName, Flags, MyFlags)); -#if defined(MSDOS) || defined(__WIN__) +#if defined(MSDOS) || defined(__WIN__) || defined(__EMX__) if (Flags & O_SHARE) - fd = sopen((my_string) FileName, (Flags & ~O_SHARE) | O_BINARY, SH_DENYNO); + fd = sopen((my_string) FileName, (Flags & ~O_SHARE) | O_BINARY, SH_DENYNO, + MY_S_IREAD | MY_S_IWRITE); else - fd = open((my_string) FileName, Flags | O_BINARY); + fd = open((my_string) FileName, Flags | O_BINARY, + MY_S_IREAD | MY_S_IWRITE); #elif !defined(NO_OPEN_3) - fd = open(FileName, Flags, 0); /* Normal unix */ + fd = open(FileName, Flags, my_umask); /* Normal unix */ #else fd = open((my_string) FileName, Flags); #endif - - if ((int) fd >= 0) - { - if ((int) fd >= MY_NFILE) - DBUG_RETURN(fd); /* safeguard */ - pthread_mutex_lock(&THR_LOCK_open); - if ((my_file_info[fd].name = (char*) my_strdup(FileName,MyFlags))) - { - my_file_opened++; - my_file_info[fd].type = FILE_BY_OPEN; - pthread_mutex_unlock(&THR_LOCK_open); - DBUG_PRINT("exit",("fd: %d",fd)); - DBUG_RETURN(fd); - } - pthread_mutex_unlock(&THR_LOCK_open); - (void) my_close(fd,MyFlags); - my_errno=ENOMEM; - } - else - my_errno=errno; - DBUG_PRINT("error",("Got error %d on open",my_errno)); - if (MyFlags & (MY_FFNF | MY_FAE | MY_WME)) - my_error(EE_FILENOTFOUND, MYF(ME_BELL+ME_WAITTANG), FileName,my_errno); - DBUG_RETURN(fd); + DBUG_RETURN(my_register_filename(fd, FileName, FILE_BY_OPEN, + EE_FILENOTFOUND, MyFlags)); } /* my_open */ @@ -66,18 +47,67 @@ int my_close(File fd, myf MyFlags) DBUG_PRINT("my",("fd: %d MyFlags: %d",fd, MyFlags)); pthread_mutex_lock(&THR_LOCK_open); - if ((err = close(fd)) != 0) + if ((err = close(fd))) { + DBUG_PRINT("error",("Got error %d on close",err)); my_errno=errno; if (MyFlags & (MY_FAE | MY_WME)) my_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG),my_filename(fd),errno); } if ((uint) fd < MY_NFILE && my_file_info[fd].type != UNOPEN) { - my_file_opened--; my_free(my_file_info[fd].name, MYF(0)); +#if defined(THREAD) && !defined(HAVE_PREAD) + pthread_mutex_destroy(&my_file_info[fd].mutex); +#endif my_file_info[fd].type = UNOPEN; + my_file_opened--; } pthread_mutex_unlock(&THR_LOCK_open); DBUG_RETURN(err); } /* my_close */ + + +File my_register_filename(File fd, const char *FileName, enum file_type + type_of_file, uint error_message_number, myf MyFlags) +{ + if ((int) fd >= 0) + { + if ((int) fd >= MY_NFILE) + { +#if defined(THREAD) && !defined(HAVE_PREAD) + (void) my_close(fd,MyFlags); + my_errno=EMFILE; + if (MyFlags & (MY_FFNF | MY_FAE | MY_WME)) + my_error(EE_OUT_OF_FILERESOURCES, MYF(ME_BELL+ME_WAITTANG), + FileName, my_errno); + return(-1); +#else + thread_safe_increment(my_file_opened,&THR_LOCK_open); +#endif + return(fd); /* safeguard */ + } + pthread_mutex_lock(&THR_LOCK_open); + if ((my_file_info[fd].name = (char*) my_strdup(FileName,MyFlags))) + { + my_file_opened++; + my_file_info[fd].type = type_of_file; +#if defined(THREAD) && !defined(HAVE_PREAD) + pthread_mutex_init(&my_file_info[fd].mutex,NULL); +#endif + pthread_mutex_unlock(&THR_LOCK_open); + DBUG_PRINT("exit",("fd: %d",fd)); + return(fd); + } + pthread_mutex_unlock(&THR_LOCK_open); + (void) my_close(fd, MyFlags); + my_errno=ENOMEM; + } + else + my_errno=errno; + DBUG_PRINT("error",("Got error %d on open",my_errno)); + if (MyFlags & (MY_FFNF | MY_FAE | MY_WME)) + my_error(error_message_number, MYF(ME_BELL+ME_WAITTANG), + FileName, my_errno); + return(fd); +} |