mirror of
https://github.com/MariaDB/server.git
synced 2025-01-28 17:54:16 +01:00
518a621adf
a lot of portability issues. Docs/manual.texi: Changed FOREIGN KEY to FOREIGN KEY constraint client/mysqladmin.c: Don't flush MASTER or SLAVE on refresh configure.in: Fix for hpux 11.0 extra/perror.c: New error message include/my_pthread.h: Portability fix for windows myisam/mi_locking.c: Ensure that locking doesn't interfere with pread/pwrite on windows myisam/sort.c: checked with purecover mysys/mf_tempfile.c: Fix for windows mysys/my_lock.c: Ensure that locking doesn't interfere with pread/pwrite on windows mysys/my_winthread.c: Portability fix sql-bench/Results/ATIS-mysql-NT_4.0: New benchmark runs sql-bench/Results/RUN-mysql-NT_4.0: New benchmark runs sql-bench/Results/alter-table-mysql-NT_4.0: New benchmark runs sql-bench/Results/big-tables-mysql-NT_4.0: New benchmark runs sql-bench/Results/connect-mysql-NT_4.0: New benchmark runs sql-bench/Results/create-mysql-NT_4.0: New benchmark runs sql-bench/Results/insert-mysql-NT_4.0: New benchmark runs sql-bench/Results/select-mysql-NT_4.0: New benchmark runs sql-bench/Results/wisconsin-mysql-NT_4.0: New benchmark runs sql-bench/crash-me.sh: Fixed things for PostgreSQL sql-bench/limits/mysql-3.23.cfg: Update for new crash-me sql-bench/limits/mysql.cfg: Update for new crash-me sql-bench/print-limit-table: Fixed position for alter table rename sql-bench/test-insert.sh: Fix for PostgreSQL sql/field.cc: Fix for default values in CREATE ... SELECT sql/field.h: Fix for default values in CREATE ... SELECT sql/log.cc: Fixed typo sql/log_event.cc: Portability fix sql/mysqlbinlog.cc: Portability fix sql/mysqld.cc: Don't turn of concurrent insert with --skip-new or --safe sql/sql_base.cc: Portability fix sql/sql_class.cc: Portability fix sql/sql_class.h: Portability fix sql/sql_parse.cc: Fix for --log-slow-queries sql/sql_repl.cc: Portability fixes sql/sql_select.cc: Fixed optimizer bug for LEFT JOIN sql/sql_select.h: Fixed optimizer bug for LEFT JOIN sql/sql_table.cc: Fix for default values in CREATE ... SELECT sql/sql_yacc.yy: Added optional AS to: CREATE TABLE foo [ AS ] SELECT ...
174 lines
4.5 KiB
C
174 lines
4.5 KiB
C
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Library General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
This library 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
|
|
Library General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
License along with this library; if not, write to the Free
|
|
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
|
MA 02111-1307, USA */
|
|
|
|
#include "mysys_priv.h"
|
|
#include <m_string.h>
|
|
#include "my_static.h"
|
|
#include "mysys_err.h"
|
|
#include <errno.h>
|
|
#ifdef HAVE_PATHS_H
|
|
#include <paths.h>
|
|
#endif
|
|
|
|
#ifdef HAVE_TEMPNAM
|
|
#ifndef MSDOS
|
|
extern char **environ;
|
|
#endif
|
|
#endif
|
|
|
|
/*
|
|
Create a temporary file in a given directory
|
|
This function should be used instead of my_tempnam() !
|
|
*/
|
|
|
|
File create_temp_file(char *to, const char *dir, const char *prefix,
|
|
int mode __attribute__((unused)),
|
|
myf MyFlags __attribute__((unused)))
|
|
{
|
|
File file= -1;
|
|
DBUG_ENTER("open_temp_file");
|
|
#if defined(_MSC_VER)
|
|
{
|
|
char temp[FN_REFLEN],*end,*res,**old_env,*temp_env[1];
|
|
old_env=environ;
|
|
if (dir)
|
|
{
|
|
end=strend(dir)-1;
|
|
if (!dir[0])
|
|
{ /* Change empty string to current dir */
|
|
to[0]= FN_CURLIB;
|
|
to[1]= 0;
|
|
dir=to;
|
|
}
|
|
else if (*end == FN_DEVCHAR)
|
|
{ /* Get current dir for drive */
|
|
_fullpath(temp,dir,FN_REFLEN);
|
|
dir=to;
|
|
}
|
|
else if (*end == FN_LIBCHAR && dir < end && end[-1] != FN_DEVCHAR)
|
|
{
|
|
strmake(to,dir,(uint) (end-dir)); /* Copy and remove last '\' */
|
|
dir=to;
|
|
}
|
|
environ=temp_env; /* Force use of dir (dir not checked) */
|
|
temp_env[0]=0;
|
|
}
|
|
if ((res=tempnam((char*) dir,(char *) prefix)))
|
|
{
|
|
strnmov(to,res,FN_REFLEN);
|
|
(*free)(res);
|
|
file=my_create(to,0, mode, MyFlags);
|
|
}
|
|
environ=old_env;
|
|
}
|
|
#elif defined(_ZTC__)
|
|
if (!dir)
|
|
dir=getenv("TMPDIR");
|
|
if ((res=tempnam((char*) dir,(char *) prefix)))
|
|
{
|
|
strnmov(to,res,FN_REFLEN);
|
|
(*free)(res);
|
|
file=my_create(to, 0, mode, MyFlags);
|
|
}
|
|
#elif defined(HAVE_MKSTEMP)
|
|
{
|
|
char prefix_buff[30];
|
|
uint pfx_len;
|
|
|
|
pfx_len=(strmov(strnmov(prefix_buff,
|
|
prefix ? prefix : "tmp.",
|
|
sizeof(prefix_buff)-7),"XXXXXX") - prefix_buff);
|
|
if (!dir && ! (dir =getenv("TMPDIR")))
|
|
dir=P_tmpdir;
|
|
if (strlen(dir)+ pfx_len > FN_REFLEN-2)
|
|
{
|
|
errno=my_errno= ENAMETOOLONG;
|
|
return 1;
|
|
}
|
|
strmov(to,dir);
|
|
strmov(convert_dirname(to),prefix);
|
|
file=mkstemp(to);
|
|
}
|
|
#elif defined(HAVE_TEMPNAM)
|
|
{
|
|
char *res,**old_env,*temp_env[1];
|
|
if (dir && !dir[0])
|
|
{ /* Change empty string to current dir */
|
|
to[0]= FN_CURLIB;
|
|
to[1]= 0;
|
|
dir=to;
|
|
}
|
|
old_env=environ;
|
|
if (dir)
|
|
{ /* Don't use TMPDIR if dir is given */
|
|
environ=temp_env;
|
|
temp_env[0]=0;
|
|
}
|
|
if ((res=tempnam((char*) dir, (char*) prefix)))
|
|
{
|
|
strnmov(to,res,FN_REFLEN);
|
|
(*free)(res);
|
|
file=my_create(to,0,
|
|
(int) (O_RDWR | O_BINARY | O_TRUNC |
|
|
O_TEMPORARY | O_SHORT_LIVED),
|
|
MYF(MY_WME));
|
|
|
|
}
|
|
else
|
|
{
|
|
DBUG_PRINT("error",("Got error: %d from tempnam",errno));
|
|
}
|
|
environ=old_env;
|
|
}
|
|
#else
|
|
{
|
|
register long uniq;
|
|
register int length;
|
|
my_string pos,end_pos;
|
|
/* Make an unique number */
|
|
pthread_mutex_lock(&THR_LOCK_open);
|
|
uniq= ((long) getpid() << 20) + (long) _my_tempnam_used++ ;
|
|
pthread_mutex_unlock(&THR_LOCK_open);
|
|
if (!dir && !(dir=getenv("TMPDIR"))) /* Use this if possibly */
|
|
dir=P_tmpdir; /* Use system default */
|
|
length=strlen(dir)+strlen(pfx)+1;
|
|
|
|
DBUG_PRINT("test",("mallocing %d byte",length+8+sizeof(TMP_EXT)+1));
|
|
if (length+8+sizeof(TMP_EXT)+1 > FN_REFLENGTH)
|
|
errno=my_errno= ENAMETOOLONG;
|
|
else
|
|
{
|
|
end_pos=strmov(to,dir);
|
|
if (end_pos != to && end_pos[-1] != FN_LIBCHAR)
|
|
*end_pos++=FN_LIBCHAR;
|
|
end_pos=strmov(end_pos,pfx);
|
|
|
|
for (length=0 ; length < 8 && uniq ; length++)
|
|
{
|
|
*end_pos++= _dig_vec[(int) (uniq & 31)];
|
|
uniq >>= 5;
|
|
}
|
|
(void) strmov(end_pos,TMP_EXT);
|
|
file=my_create(to,0,
|
|
(int) (O_RDWR | O_BINARY | O_TRUNC |
|
|
O_TEMPORARY | O_SHORT_LIVED),
|
|
MYF(MY_WME));
|
|
}
|
|
}
|
|
#endif
|
|
DBUG_RETURN(file);
|
|
}
|