~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_path.c

  • Committer: Brian Aker
  • Date: 2008-07-15 06:45:16 UTC
  • Revision ID: brian@tangent.org-20080715064516-fnbq7kowh7w57bxj
Merge Monty's code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
#include "mysys_priv.h"
17
 
#include <mystrings/m_string.h>
 
17
#include <m_string.h>
18
18
#include "my_static.h"
19
19
 
20
20
static char *find_file_in_path(char *to,const char *name);
35
35
{
36
36
  char *start, *end, *prog;
37
37
  size_t to_length;
 
38
  DBUG_ENTER("my_path");
38
39
 
39
40
  start=to;                                     /* Return this */
40
41
  if (progname && (dirname_part(to, progname, &to_length) ||
42
43
                   ((prog=getenv("_")) != 0 &&
43
44
                    dirname_part(to, prog, &to_length))))
44
45
  {
45
 
    intern_filename(to,to);
 
46
    VOID(intern_filename(to,to));
46
47
    if (!test_if_hard_path(to))
47
48
    {
48
49
      if (!my_getwd(curr_dir,FN_REFLEN,MYF(0)))
49
 
        bchange((unsigned char*) to, 0, (unsigned char*) curr_dir, strlen(curr_dir), strlen(to)+1);
 
50
        bchange((uchar*) to, 0, (uchar*) curr_dir, strlen(curr_dir), strlen(to)+1);
50
51
    }
51
52
  }
52
53
  else
60
61
      end= (char*) "/my/";
61
62
#endif
62
63
    }
63
 
    intern_filename(to,end);
64
 
    to= strchr(to, '\0');
 
64
    VOID(intern_filename(to,end));
 
65
    to=strend(to);
65
66
    if (to != start && to[-1] != FN_LIBCHAR)
66
67
      *to++ = FN_LIBCHAR;
67
 
    my_stpcpy(to,own_pathname_part);
 
68
    VOID(strmov(to,own_pathname_part));
68
69
  }
69
 
  return(start);
 
70
  DBUG_PRINT("exit",("to: '%s'",start));
 
71
  DBUG_RETURN(start);
70
72
} /* my_path */
71
73
 
72
74
 
73
75
        /* test if file without filename is found in path */
74
 
        /* Returns to if found and to has dirpart if found, else NULL */
 
76
        /* Returns to if found and to has dirpart if found, else NullS */
75
77
 
76
78
#define PATH_SEP ':'
77
79
 
81
83
  const char *ext="";
82
84
 
83
85
  if (!(path=getenv("PATH")))
84
 
    return NULL;
 
86
    return NullS;
85
87
  dir[0]=FN_LIBCHAR; dir[1]=0;
86
88
#ifdef PROGRAM_EXTENSION
87
89
  if (!fn_ext(name)[0])
92
94
  {
93
95
    if (path != pos)
94
96
    {
95
 
      strxmov(my_stpncpy(to,path,(uint) (pos-path)),dir,name,ext,NULL);
 
97
      strxmov(strnmov(to,path,(uint) (pos-path)),dir,name,ext,NullS);
96
98
      if (!access(to,F_OK))
97
99
      {
98
100
        to[(uint) (pos-path)+1]=0;      /* Return path only */
100
102
      }
101
103
    }
102
104
  }
103
 
  return NULL;                          /* File not found */
 
105
  return NullS;                         /* File not found */
104
106
}