~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_tempfile.c

  • Committer: Monty Taylor
  • Date: 2008-09-15 17:24:04 UTC
  • Revision ID: monty@inaugust.com-20080915172404-ygh6hiyu0q7qpa9x
Removed strndup calls.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
    implementation, it's main use is to generate a file with
46
46
    a name that does not already exist.
47
47
 
 
48
    When passing O_TEMPORARY flag in "mode" the file should
 
49
    be automatically deleted
 
50
 
48
51
    The implementation using mkstemp should be considered the
49
52
    reference implementation when adding a new or modifying an
50
53
    existing one
64
67
  {
65
68
    strmake(to,res,FN_REFLEN-1);
66
69
    (*free)(res);
67
 
    file=my_create(to, 0, mode | O_EXCL, MyFlags);
 
70
    file=my_create(to, 0, mode | O_EXCL | O_NOFOLLOW, MyFlags);
68
71
  }
69
72
#elif defined(HAVE_MKSTEMP)
70
73
  {
71
74
    char prefix_buff[30];
72
 
    uint32_t pfx_len;
 
75
    uint pfx_len;
73
76
    File org_file;
74
77
 
75
 
    pfx_len= (uint) (my_stpcpy(my_stpncpy(prefix_buff,
 
78
    pfx_len= (uint) (stpcpy(stpncpy(prefix_buff,
76
79
                                    prefix ? prefix : "tmp.",
77
80
                                    sizeof(prefix_buff)-7),"XXXXXX") -
78
81
                     prefix_buff);
83
86
      errno=my_errno= ENAMETOOLONG;
84
87
      return(file);
85
88
    }
86
 
    my_stpcpy(convert_dirname(to,dir,NULL),prefix_buff);
 
89
    stpcpy(convert_dirname(to,dir,NullS),prefix_buff);
87
90
    org_file=mkstemp(to);
88
 
    /* TODO: This was old behavior, but really don't we want to 
89
 
     * unlink files immediately under all circumstances?
90
 
     * if (mode & O_TEMPORARY)
 
91
    if (mode & O_TEMPORARY)
91
92
      (void) my_delete(to, MYF(MY_WME | ME_NOINPUT));
92
 
     */
93
93
    file=my_register_filename(org_file, to, FILE_BY_MKSTEMP,
94
94
                              EE_CANTCREATEFILE, MyFlags);
95
95
    /* If we didn't manage to register the name, remove the temp file */
121
121
      strmake(to,res,FN_REFLEN-1);
122
122
      (*free)(res);
123
123
      file=my_create(to,0,
124
 
                     (int) (O_RDWR | O_TRUNC | O_EXCL),
 
124
                     (int) (O_RDWR | O_BINARY | O_TRUNC | O_EXCL | O_NOFOLLOW |
 
125
                            O_TEMPORARY | O_SHORT_LIVED),
125
126
                     MYF(MY_WME));
126
127
 
127
128
    }