~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_pack.cc

  • Committer: Brian Aker
  • Date: 2009-02-21 00:18:15 UTC
  • Revision ID: brian@tangent.org-20090221001815-x20e8h71e984lvs1
Completion (?) of uint conversion.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
   You should have received a copy of the GNU General Public License
13
13
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
 
 
16
 
#include "config.h"
17
 
 
18
 
#include "drizzled/internal/my_sys.h"
19
 
 
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#include "mysys_priv.h"
 
17
#include <mystrings/m_string.h>
 
18
#include "my_static.h"
 
19
#ifdef HAVE_PWD_H
20
20
#include <pwd.h>
21
 
 
22
 
#include "drizzled/internal/m_string.h"
23
 
#include "my_static.h"
24
 
 
25
 
namespace drizzled
26
 
{
27
 
namespace internal
28
 
{
 
21
#endif
29
22
 
30
23
static char * expand_tilde(char * *path);
31
 
static size_t system_filename(char * to, const char *from);
 
24
 
32
25
 
33
26
/*
34
27
  remove unwanted chars from dirname
50
43
    #  length of new name
51
44
*/
52
45
 
53
 
static size_t cleanup_dirname(register char *to, const char *from)
 
46
size_t cleanup_dirname(register char *to, const char *from)
54
47
{
55
48
  register size_t length;
56
49
  register char * pos;
58
51
  register char * start;
59
52
  char parent[5],                               /* for "FN_PARENTDIR" */
60
53
       buff[FN_REFLEN+1],*end_parentdir;
 
54
#ifdef BACKSLASH_MBTAIL
 
55
  CHARSET_INFO *fs= fs_character_set();
 
56
#endif
61
57
 
62
58
  start=buff;
63
59
  from_ptr= from;
164
160
 
165
161
bool my_use_symdir=0;   /* Set this if you want to use symdirs */
166
162
 
 
163
#ifdef USE_SYMDIR
 
164
void symdirget(char *dir)
 
165
{
 
166
  char buff[FN_REFLEN];
 
167
  char *pos= strchr(dir, '\0');
 
168
  if (dir[0] && pos[-1] != FN_DEVCHAR && my_access(dir, F_OK))
 
169
  {
 
170
    File file;
 
171
    size_t length;
 
172
    char temp= *(--pos);            /* May be "/" or "\" */
 
173
    strcpy(pos,".sym");
 
174
    file= my_open(dir, O_RDONLY, MYF(0));
 
175
    *pos++=temp; *pos=0;          /* Restore old filename */
 
176
    if (file >= 0)
 
177
    {
 
178
      if ((length= my_read(file, buff, sizeof(buff), MYF(0))) > 0)
 
179
      {
 
180
        for (pos= buff + length ;
 
181
             pos > buff && (iscntrl(pos[-1]) || isspace(pos[-1])) ;
 
182
             pos --);
 
183
 
 
184
        /* Ensure that the symlink ends with the directory symbol */
 
185
        if (pos == buff || pos[-1] != FN_LIBCHAR)
 
186
          *pos++=FN_LIBCHAR;
 
187
 
 
188
        strncpy(dir,buff, FN_REFLEN-1);
 
189
      }
 
190
      my_close(file, MYF(0));
 
191
    }
 
192
  }
 
193
}
 
194
#endif /* USE_SYMDIR */
 
195
 
167
196
 
168
197
/*
169
198
  Fixes a directroy name so that can be used by open()
220
249
      }
221
250
    }
222
251
  }
 
252
#ifdef USE_SYMDIR
 
253
  if (my_use_symdir)
 
254
    symdirget(buff);
 
255
#endif
223
256
  return(system_filename(to,buff));     /* Fix for open */
224
257
} /* unpack_dirname */
225
258
 
231
264
{
232
265
  if (path[0][0] == FN_LIBCHAR)
233
266
    return home_dir;                    /* ~/ expanded to home */
234
 
  char *str,save;
235
 
  struct passwd *user_entry;
 
267
#ifdef HAVE_GETPWNAM
 
268
  {
 
269
    char *str,save;
 
270
    struct passwd *user_entry;
236
271
 
237
 
  if (!(str=strchr(*path,FN_LIBCHAR)))
238
 
    str= strchr(*path, '\0');
239
 
  save= *str; *str= '\0';
240
 
  user_entry=getpwnam(*path);
241
 
  *str=save;
242
 
  endpwent();
243
 
  if (user_entry)
244
 
  {
245
 
    *path=str;
246
 
    return user_entry->pw_dir;
 
272
    if (!(str=strchr(*path,FN_LIBCHAR)))
 
273
      str= strchr(*path, '\0');
 
274
    save= *str; *str= '\0';
 
275
    user_entry=getpwnam(*path);
 
276
    *str=save;
 
277
    endpwent();
 
278
    if (user_entry)
 
279
    {
 
280
      *path=str;
 
281
      return user_entry->pw_dir;
 
282
    }
247
283
  }
 
284
#endif
248
285
  return NULL;
249
286
}
250
287
 
288
325
        /* Used before system command's like open(), create() .. */
289
326
        /* Returns used length of to; total length should be FN_REFLEN */
290
327
 
291
 
static size_t system_filename(char * to, const char *from)
 
328
size_t system_filename(char * to, const char *from)
292
329
{
 
330
#ifndef FN_C_BEFORE_DIR
293
331
  return strlen(strncpy(to,from,FN_REFLEN-1));
 
332
#else   /* VMS */
 
333
 
 
334
        /* change 'dev:lib/xxx' to 'dev:[lib]xxx' */
 
335
        /* change 'dev:xxx' to 'dev:xxx' */
 
336
        /* change './xxx' to 'xxx' */
 
337
        /* change './lib/' or lib/ to '[.lib]' */
 
338
        /* change '/x/y/z to '[x.y]x' */
 
339
        /* change 'dev:/x' to 'dev:[000000]x' */
 
340
 
 
341
  int libchar_found;
 
342
  size_t length;
 
343
  char * to_pos,from_pos,pos;
 
344
  char buff[FN_REFLEN];
 
345
 
 
346
  libchar_found=0;
 
347
  (void) strcpy(buff,from);                      /* If to == from */
 
348
  from_pos= buff;
 
349
  if ((pos=strrchr(from_pos,FN_DEVCHAR)))       /* Skip device part */
 
350
  {
 
351
    pos++;
 
352
    to_pos= strncpy(to,from_pos,(size_t) (pos-from_pos));
 
353
    to_pos+= strlen(to);
 
354
    from_pos=pos;
 
355
  }
 
356
  else
 
357
    to_pos=to;
 
358
 
 
359
  if (from_pos[0] == FN_CURLIB && from_pos[1] == FN_LIBCHAR)
 
360
    from_pos+=2;                                /* Skip './' */
 
361
  if (strchr(from_pos,FN_LIBCHAR))
 
362
  {
 
363
    *(to_pos++) = FN_C_BEFORE_DIR;
 
364
    if (strstr(from_pos,FN_ROOTDIR) == from_pos)
 
365
    {
 
366
      from_pos+=strlen(FN_ROOTDIR);             /* Actually +1 but... */
 
367
      if (! strchr(from_pos,FN_LIBCHAR))
 
368
      {                                         /* No dir, use [000000] */
 
369
        to_pos= strcpy(to_pos,FN_C_ROOT_DIR)+strlen(FN_C_ROOT_DIR);
 
370
        libchar_found++;
 
371
      }
 
372
    }
 
373
    else
 
374
      *(to_pos++)=FN_C_DIR_SEP;                 /* '.' gives current dir */
 
375
 
 
376
    while ((pos=strchr(from_pos,FN_LIBCHAR)))
 
377
    {
 
378
      if (libchar_found++)
 
379
        *(to_pos++)=FN_C_DIR_SEP;               /* Add '.' between dirs */
 
380
      if (strstr(from_pos,FN_PARENTDIR) == from_pos &&
 
381
          from_pos+strlen(FN_PARENTDIR) == pos) {
 
382
        to_pos= strcpy(to_pos,FN_C_PARENT_DIR); /* Found '../' */
 
383
        to_pos+= strlen(FN_C_PARENT_DIR);
 
384
      }
 
385
      else
 
386
      {
 
387
        to_pos= strncpy(to_pos,from_pos,(size_t) (pos-from_pos));
 
388
        to_pos+= strlen(to_pos);
 
389
      }
 
390
      from_pos=pos+1;
 
391
    }
 
392
    *(to_pos++)=FN_C_AFTER_DIR;
 
393
  }
 
394
 
 
395
  strcpy(to_pos, from_pos);
 
396
  length= strlen(to);
 
397
  return(length);
 
398
#endif
294
399
} /* system_filename */
295
400
 
296
401
 
309
414
  (void) strcpy(to + to_length,from+length);
310
415
  return (to);
311
416
} /* intern_filename */
312
 
 
313
 
} /* namespace internal */
314
 
} /* namespace drizzled */