2011-01-25 15:42:40 +01:00
|
|
|
/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
|
2001-12-06 13:10:51 +01:00
|
|
|
|
|
|
|
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
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2001-12-06 13:10:51 +01:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
2000-07-31 21:29:14 +02:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2001-12-06 13:10:51 +01:00
|
|
|
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 */
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
#include "mysys_priv.h"
|
|
|
|
#include "my_static.h"
|
|
|
|
#include <errno.h>
|
|
|
|
#include "mysys_err.h"
|
|
|
|
|
2011-01-07 19:33:36 +01:00
|
|
|
#if defined(__FreeBSD__)
|
|
|
|
extern int getosreldate(void);
|
|
|
|
#endif
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
static void make_ftype(char * to,int flag);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2005-06-21 17:18:58 +02:00
|
|
|
/*
|
|
|
|
Open a file as stream
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2005-06-21 17:18:58 +02:00
|
|
|
SYNOPSIS
|
|
|
|
my_fopen()
|
|
|
|
FileName Path-name of file
|
|
|
|
Flags Read | write | append | trunc (like for open())
|
|
|
|
MyFlags Flags for handling errors
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 Error
|
|
|
|
# File handler
|
|
|
|
*/
|
|
|
|
|
|
|
|
FILE *my_fopen(const char *filename, int flags, myf MyFlags)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
FILE *fd;
|
|
|
|
char type[5];
|
|
|
|
DBUG_ENTER("my_fopen");
|
2005-06-21 17:18:58 +02:00
|
|
|
DBUG_PRINT("my",("Name: '%s' flags: %d MyFlags: %d",
|
|
|
|
filename, flags, MyFlags));
|
2005-05-21 19:31:58 +02:00
|
|
|
/*
|
2005-05-23 21:48:25 +02:00
|
|
|
if we are not creating, then we need to use my_access to make sure
|
|
|
|
the file exists since Windows doesn't handle files like "com1.sym"
|
|
|
|
very well
|
2005-05-21 19:31:58 +02:00
|
|
|
*/
|
|
|
|
#ifdef __WIN__
|
2005-06-21 17:18:58 +02:00
|
|
|
if (check_if_legal_filename(filename))
|
2005-05-25 11:56:47 +02:00
|
|
|
{
|
|
|
|
errno= EACCES;
|
|
|
|
fd= 0;
|
|
|
|
}
|
2005-05-21 19:31:58 +02:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2005-06-21 17:18:58 +02:00
|
|
|
make_ftype(type,flags);
|
|
|
|
fd = fopen(filename, type);
|
2005-05-21 19:31:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fd != 0)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
The test works if MY_NFILE < 128. The problem is that fileno() is char
|
|
|
|
on some OS (SUNOS). Actually the filename save isn't that important
|
|
|
|
so we can ignore if this doesn't work.
|
|
|
|
*/
|
2004-02-19 18:33:09 +01:00
|
|
|
if ((uint) fileno(fd) >= my_file_limit)
|
2000-09-12 02:02:33 +02:00
|
|
|
{
|
|
|
|
thread_safe_increment(my_stream_opened,&THR_LOCK_open);
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(fd); /* safeguard */
|
2000-09-12 02:02:33 +02:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
pthread_mutex_lock(&THR_LOCK_open);
|
|
|
|
if ((my_file_info[fileno(fd)].name = (char*)
|
2005-06-21 17:18:58 +02:00
|
|
|
my_strdup(filename,MyFlags)))
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
my_stream_opened++;
|
2007-08-13 15:11:25 +02:00
|
|
|
my_file_total_opened++;
|
2000-07-31 21:29:14 +02:00
|
|
|
my_file_info[fileno(fd)].type = STREAM_BY_FOPEN;
|
|
|
|
pthread_mutex_unlock(&THR_LOCK_open);
|
2006-11-20 21:42:06 +01:00
|
|
|
DBUG_PRINT("exit",("stream: 0x%lx", (long) fd));
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(fd);
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&THR_LOCK_open);
|
|
|
|
(void) my_fclose(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))
|
2005-06-21 17:18:58 +02:00
|
|
|
my_error((flags & O_RDONLY) || (flags == O_RDONLY ) ? EE_FILENOTFOUND :
|
2000-07-31 21:29:14 +02:00
|
|
|
EE_CANTCREATEFILE,
|
2005-06-21 17:18:58 +02:00
|
|
|
MYF(ME_BELL+ME_WAITTANG), filename, my_errno);
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN((FILE*) 0);
|
|
|
|
} /* my_fopen */
|
|
|
|
|
|
|
|
|
2011-01-07 19:33:36 +01:00
|
|
|
#if defined(_WIN32)
|
|
|
|
|
2011-01-07 20:28:06 +01:00
|
|
|
static FILE *my_win_freopen(const char *path, const char *mode, FILE *stream)
|
2011-01-07 19:33:36 +01:00
|
|
|
{
|
|
|
|
int handle_fd, fd= _fileno(stream);
|
|
|
|
HANDLE osfh;
|
|
|
|
|
2011-01-07 20:28:06 +01:00
|
|
|
DBUG_ASSERT(path && stream);
|
2011-01-07 19:33:36 +01:00
|
|
|
|
|
|
|
/* Services don't have stdout/stderr on Windows, so _fileno returns -1. */
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
2011-01-07 20:28:06 +01:00
|
|
|
if (!freopen(path, mode, stream))
|
2011-01-07 19:33:36 +01:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
fd= _fileno(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((osfh= CreateFile(path, GENERIC_READ | GENERIC_WRITE,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE |
|
|
|
|
FILE_SHARE_DELETE, NULL,
|
|
|
|
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL,
|
|
|
|
NULL)) == INVALID_HANDLE_VALUE)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if ((handle_fd= _open_osfhandle((intptr_t)osfh,
|
|
|
|
_O_APPEND | _O_TEXT)) == -1)
|
|
|
|
{
|
|
|
|
CloseHandle(osfh);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_dup2(handle_fd, fd) < 0)
|
|
|
|
{
|
|
|
|
CloseHandle(osfh);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
_close(handle_fd);
|
|
|
|
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(__FreeBSD__)
|
|
|
|
|
|
|
|
/* No close operation hook. */
|
|
|
|
|
|
|
|
static int no_close(void *cookie __attribute__((unused)))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
A hack around a race condition in the implementation of freopen.
|
|
|
|
|
|
|
|
The race condition steams from the fact that the current fd of
|
|
|
|
the stream is closed before its number is used to duplicate the
|
|
|
|
new file descriptor. This defeats the desired atomicity of the
|
|
|
|
close and duplicate of dup2().
|
|
|
|
|
|
|
|
See PR number 79887 for reference:
|
|
|
|
http://www.freebsd.org/cgi/query-pr.cgi?pr=79887
|
|
|
|
*/
|
|
|
|
|
|
|
|
static FILE *my_freebsd_freopen(const char *path, const char *mode, FILE *stream)
|
|
|
|
{
|
|
|
|
int old_fd;
|
|
|
|
FILE *result;
|
|
|
|
|
|
|
|
flockfile(stream);
|
|
|
|
|
|
|
|
old_fd= fileno(stream);
|
|
|
|
|
|
|
|
/* Use a no operation close hook to avoid having the fd closed. */
|
|
|
|
stream->_close= no_close;
|
|
|
|
|
|
|
|
/* Relies on the implicit dup2 to close old_fd. */
|
|
|
|
result= freopen(path, mode, stream);
|
|
|
|
|
|
|
|
/* If successful, the _close hook was replaced. */
|
|
|
|
|
|
|
|
if (result == NULL)
|
|
|
|
close(old_fd);
|
|
|
|
else
|
|
|
|
funlockfile(result);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Change the file associated with a file stream.
|
|
|
|
|
|
|
|
@param path Path to file.
|
|
|
|
@param mode Mode of the stream.
|
|
|
|
@param stream File stream.
|
|
|
|
|
|
|
|
@note
|
|
|
|
This function is used to redirect stdout and stderr to a file and
|
|
|
|
subsequently to close and reopen that file for log rotation.
|
|
|
|
|
|
|
|
@retval A FILE pointer on success. Otherwise, NULL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
FILE *my_freopen(const char *path, const char *mode, FILE *stream)
|
|
|
|
{
|
|
|
|
FILE *result;
|
|
|
|
|
|
|
|
#if defined(_WIN32)
|
|
|
|
result= my_win_freopen(path, mode, stream);
|
|
|
|
#elif defined(__FreeBSD__)
|
|
|
|
/*
|
|
|
|
XXX: Once the fix is ported to the stable releases, this should
|
|
|
|
be dependent upon the specific FreeBSD versions. Check at:
|
|
|
|
http://www.freebsd.org/cgi/query-pr.cgi?pr=79887
|
|
|
|
*/
|
|
|
|
if (getosreldate() > 900027)
|
|
|
|
result= freopen(path, mode, stream);
|
|
|
|
else
|
|
|
|
result= my_freebsd_freopen(path, mode, stream);
|
|
|
|
#else
|
|
|
|
result= freopen(path, mode, stream);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2011-01-07 19:33:36 +01:00
|
|
|
/* Close a stream */
|
2000-07-31 21:29:14 +02:00
|
|
|
int my_fclose(FILE *fd, myf MyFlags)
|
|
|
|
{
|
|
|
|
int err,file;
|
|
|
|
DBUG_ENTER("my_fclose");
|
2006-11-20 21:42:06 +01:00
|
|
|
DBUG_PRINT("my",("stream: 0x%lx MyFlags: %d", (long) fd, MyFlags));
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
pthread_mutex_lock(&THR_LOCK_open);
|
|
|
|
file=fileno(fd);
|
|
|
|
if ((err = fclose(fd)) < 0)
|
|
|
|
{
|
|
|
|
my_errno=errno;
|
|
|
|
if (MyFlags & (MY_FAE | MY_WME))
|
|
|
|
my_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG),
|
|
|
|
my_filename(file),errno);
|
|
|
|
}
|
2000-09-12 02:02:33 +02:00
|
|
|
else
|
|
|
|
my_stream_opened--;
|
2004-02-19 18:33:09 +01:00
|
|
|
if ((uint) file < my_file_limit && my_file_info[file].type != UNOPEN)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
my_file_info[file].type = UNOPEN;
|
2000-10-03 13:18:03 +02:00
|
|
|
my_free(my_file_info[file].name, MYF(MY_ALLOW_ZERO_PTR));
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&THR_LOCK_open);
|
|
|
|
DBUG_RETURN(err);
|
|
|
|
} /* my_fclose */
|
|
|
|
|
|
|
|
|
|
|
|
/* Make a stream out of a file handle */
|
2000-10-03 13:18:03 +02:00
|
|
|
/* Name may be 0 */
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2000-10-03 13:18:03 +02:00
|
|
|
FILE *my_fdopen(File Filedes, const char *name, int Flags, myf MyFlags)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
FILE *fd;
|
|
|
|
char type[5];
|
|
|
|
DBUG_ENTER("my_fdopen");
|
|
|
|
DBUG_PRINT("my",("Fd: %d Flags: %d MyFlags: %d",
|
|
|
|
Filedes, Flags, MyFlags));
|
|
|
|
|
|
|
|
make_ftype(type,Flags);
|
|
|
|
if ((fd = fdopen(Filedes, type)) == 0)
|
|
|
|
{
|
|
|
|
my_errno=errno;
|
|
|
|
if (MyFlags & (MY_FAE | MY_WME))
|
|
|
|
my_error(EE_CANT_OPEN_STREAM, MYF(ME_BELL+ME_WAITTANG),errno);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&THR_LOCK_open);
|
2000-10-03 13:18:03 +02:00
|
|
|
my_stream_opened++;
|
2004-02-19 18:33:09 +01:00
|
|
|
if ((uint) Filedes < (uint) my_file_limit)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2000-10-03 13:18:03 +02:00
|
|
|
if (my_file_info[Filedes].type != UNOPEN)
|
|
|
|
{
|
2004-02-19 18:33:09 +01:00
|
|
|
my_file_opened--; /* File is opened with my_open ! */
|
2000-10-03 13:18:03 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
my_file_info[Filedes].name= my_strdup(name,MyFlags);
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
my_file_info[Filedes].type = STREAM_BY_FDOPEN;
|
|
|
|
}
|
|
|
|
pthread_mutex_unlock(&THR_LOCK_open);
|
|
|
|
}
|
|
|
|
|
2006-11-20 21:42:06 +01:00
|
|
|
DBUG_PRINT("exit",("stream: 0x%lx", (long) fd));
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_RETURN(fd);
|
|
|
|
} /* my_fdopen */
|
|
|
|
|
2005-06-21 17:18:58 +02:00
|
|
|
|
2005-06-07 22:45:03 +02:00
|
|
|
/*
|
2005-06-21 17:18:58 +02:00
|
|
|
Make a fopen() typestring from a open() type bitmap
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
make_ftype()
|
|
|
|
to String for fopen() is stored here
|
|
|
|
flag Flag used by open()
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2005-06-21 17:18:58 +02:00
|
|
|
IMPLEMENTATION
|
|
|
|
This routine attempts to find the best possible match
|
|
|
|
between a numeric option and a string option that could be
|
|
|
|
fed to fopen. There is not a 1 to 1 mapping between the two.
|
2005-06-07 22:45:03 +02:00
|
|
|
|
2005-06-21 17:18:58 +02:00
|
|
|
NOTE
|
|
|
|
On Unix, O_RDONLY is usually 0
|
|
|
|
|
|
|
|
MAPPING
|
|
|
|
r == O_RDONLY
|
|
|
|
w == O_WRONLY|O_TRUNC|O_CREAT
|
|
|
|
a == O_WRONLY|O_APPEND|O_CREAT
|
|
|
|
r+ == O_RDWR
|
|
|
|
w+ == O_RDWR|O_TRUNC|O_CREAT
|
|
|
|
a+ == O_RDWR|O_APPEND|O_CREAT
|
2005-06-07 22:45:03 +02:00
|
|
|
*/
|
2005-06-21 17:18:58 +02:00
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
static void make_ftype(register char * to, register int flag)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2005-06-07 22:45:03 +02:00
|
|
|
/* check some possible invalid combinations */
|
2005-06-21 17:18:58 +02:00
|
|
|
DBUG_ASSERT((flag & (O_TRUNC | O_APPEND)) != (O_TRUNC | O_APPEND));
|
|
|
|
DBUG_ASSERT((flag & (O_WRONLY | O_RDWR)) != (O_WRONLY | O_RDWR));
|
2005-06-07 22:45:03 +02:00
|
|
|
|
2005-06-21 17:18:58 +02:00
|
|
|
if ((flag & (O_RDONLY|O_WRONLY)) == O_WRONLY)
|
2005-06-09 10:13:02 +02:00
|
|
|
*to++= (flag & O_APPEND) ? 'a' : 'w';
|
2005-06-07 22:45:03 +02:00
|
|
|
else if (flag & O_RDWR)
|
|
|
|
{
|
|
|
|
/* Add '+' after theese */
|
2005-06-09 10:13:02 +02:00
|
|
|
if (flag & (O_TRUNC | O_CREAT))
|
2005-06-07 22:45:03 +02:00
|
|
|
*to++= 'w';
|
|
|
|
else if (flag & O_APPEND)
|
|
|
|
*to++= 'a';
|
|
|
|
else
|
2000-07-31 21:29:14 +02:00
|
|
|
*to++= 'r';
|
2005-06-07 22:45:03 +02:00
|
|
|
*to++= '+';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*to++= 'r';
|
|
|
|
|
|
|
|
#if FILE_BINARY /* If we have binary-files */
|
2005-06-21 17:18:58 +02:00
|
|
|
if (flag & FILE_BINARY)
|
2000-07-31 21:29:14 +02:00
|
|
|
*to++='b';
|
2005-06-07 22:45:03 +02:00
|
|
|
#endif
|
2000-07-31 21:29:14 +02:00
|
|
|
*to='\0';
|
|
|
|
} /* make_ftype */
|