~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_tempfile.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-06-20 03:05:30 UTC
  • mto: (1076.2.5 info-schema-plugin)
  • mto: This revision was merged to the branch mainline in revision 1073.
  • Revision ID: osullivan.padraig@gmail.com-20090620030530-d3tdkf9pbaoiv4i6
Created an I_S plugin. Extracted the PROCESSLIST table into this plugin and
removed any trace of it from show.cc

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
#include "drizzled/internal/mysys_priv.h"
17
 
#include "drizzled/internal/m_string.h"
 
16
#include "mysys/mysys_priv.h"
 
17
#include <mystrings/m_string.h>
18
18
#include "my_static.h"
19
 
#include "drizzled/my_error.h"
 
19
#include "mysys/mysys_err.h"
20
20
#include <stdio.h>
21
21
#include <errno.h>
22
22
#include <string>
52
52
 
53
53
*/
54
54
 
55
 
int create_temp_file(char *to, const char *dir, const char *prefix,
56
 
                     myf MyFlags)
 
55
File create_temp_file(char *to, const char *dir, const char *prefix, myf MyFlags)
57
56
{
58
 
  int file= -1;
59
 
 
60
 
  int org_file;
61
 
  string prefix_str;
62
 
 
63
 
  prefix_str= prefix ? prefix : "tmp.";
64
 
  prefix_str.append("XXXXXX");
65
 
 
66
 
  if (!dir && ! (dir =getenv("TMPDIR")))
67
 
    dir= P_tmpdir;
68
 
  if (strlen(dir)+prefix_str.length() > FN_REFLEN-2)
69
 
  {
70
 
    errno=errno= ENAMETOOLONG;
71
 
    return(file);
72
 
  }
73
 
  strcpy(convert_dirname(to,dir,NULL),prefix_str.c_str());
74
 
  org_file=mkstemp(to);
75
 
  /* TODO: This was old behavior, but really don't we want to
76
 
   * unlink files immediately under all circumstances?
77
 
   * if (mode & O_TEMPORARY)
78
 
    (void) my_delete(to, MYF(MY_WME | ME_NOINPUT));
79
 
  */
80
 
  file=my_register_filename(org_file, to, EE_CANTCREATEFILE, MyFlags);
81
 
 
82
 
  /* If we didn't manage to register the name, remove the temp file */
83
 
  if (org_file >= 0 && file < 0)
84
 
  {
85
 
    int tmp=errno;
86
 
    close(org_file);
87
 
    (void) my_delete(to, MYF(MY_WME | ME_NOINPUT));
88
 
    errno=tmp;
89
 
  }
 
57
  File file= -1;
 
58
 
 
59
#if defined(_ZTC__)
 
60
  if (!dir)
 
61
    dir=getenv("TMPDIR");
 
62
  if ((res=tempnam((char*) dir,(char *) prefix)))
 
63
  {
 
64
    strncpy(to,res,FN_REFLEN-1);
 
65
    (*free)(res);
 
66
    file=my_create(to, 0, mode | O_EXCL, MyFlags);
 
67
  }
 
68
#elif defined(HAVE_MKSTEMP)
 
69
  {
 
70
    File org_file;
 
71
    string prefix_str;
 
72
 
 
73
    prefix_str= prefix ? prefix : "tmp.";
 
74
    prefix_str.append("XXXXXX");
 
75
 
 
76
    if (!dir && ! (dir =getenv("TMPDIR")))
 
77
      dir= P_tmpdir;
 
78
    if (strlen(dir)+prefix_str.length() > FN_REFLEN-2)
 
79
    {
 
80
      errno=my_errno= ENAMETOOLONG;
 
81
      return(file);
 
82
    }
 
83
    strcpy(convert_dirname(to,dir,NULL),prefix_str.c_str());
 
84
    org_file=mkstemp(to);
 
85
    /* TODO: This was old behavior, but really don't we want to
 
86
     * unlink files immediately under all circumstances?
 
87
     * if (mode & O_TEMPORARY)
 
88
      (void) my_delete(to, MYF(MY_WME | ME_NOINPUT));
 
89
     */
 
90
    file=my_register_filename(org_file, to, EE_CANTCREATEFILE, MyFlags);
 
91
 
 
92
    /* If we didn't manage to register the name, remove the temp file */
 
93
    if (org_file >= 0 && file < 0)
 
94
    {
 
95
      int tmp=my_errno;
 
96
      close(org_file);
 
97
      (void) my_delete(to, MYF(MY_WME | ME_NOINPUT));
 
98
      my_errno=tmp;
 
99
    }
 
100
  }
 
101
#elif defined(HAVE_TEMPNAM)
 
102
  {
 
103
    (void)MyFlags;
 
104
    char *res,**old_env,*temp_env[1];
 
105
    if (dir && !dir[0])
 
106
    {                           /* Change empty string to current dir */
 
107
      to[0]= FN_CURLIB;
 
108
      to[1]= 0;
 
109
      dir=to;
 
110
    }
 
111
    old_env= (char**) environ;
 
112
    if (dir)
 
113
    {                           /* Don't use TMPDIR if dir is given */
 
114
      environ=(const char**) temp_env;
 
115
      temp_env[0]=0;
 
116
    }
 
117
    if ((res=tempnam((char*) dir, (char*) prefix)))
 
118
    {
 
119
      strncpy(to,res,FN_REFLEN-1);
 
120
      (*free)(res);
 
121
      file=my_create(to,0,
 
122
                     (int) (O_RDWR | O_TRUNC | O_EXCL),
 
123
                     MYF(MY_WME));
 
124
 
 
125
    }
 
126
    environ=(const char**) old_env;
 
127
  }
 
128
#else
 
129
#error No implementation found for create_temp_file
 
130
#endif
90
131
  if (file >= 0)
91
132
    my_tmp_file_created++;
92
133