Example #1
0
size_t normalize_dirname(char *to, const char *from)
{
  size_t length;
  char buff[FN_REFLEN];
  DBUG_ENTER("normalize_dirname");

  /*
    Despite the name, this actually converts the name to the system's
    format (TODO: name this properly).
  */
  (void) intern_filename(buff, from);
  length= strlen(buff);			/* Fix that '/' is last */
  if (length &&
#ifdef FN_DEVCHAR
      buff[length - 1] != FN_DEVCHAR &&
#endif
      buff[length - 1] != FN_LIBCHAR && buff[length - 1] != '/')
  {
    /* we need reserve 2 bytes for the trailing slash and the zero */
    if (length >= sizeof (buff) - 1)
      length= sizeof (buff) - 2;
    buff[length]= FN_LIBCHAR;
    buff[length + 1]= '\0';
  }

  length=cleanup_dirname(to, buff);

  DBUG_RETURN(length);
}
Example #2
0
my_bool my_init(void)
{
  char * str;
  if (my_init_done)
    return 0;
  my_init_done=1;
  mysys_usage_id++;
  my_umask= 0660;                       /* Default umask for new files */
  my_umask_dir= 0700;                   /* Default umask for new directories */
  init_glob_errs();
#if defined(THREAD)
  if (my_thread_global_init())
    return 1;
#  if defined(SAFE_MUTEX)
  safe_mutex_global_init();		/* Must be called early */
#  endif
#endif
#if defined(THREAD) && defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX)
  fastmutex_global_init();              /* Must be called early */
#endif
  netware_init();
#ifdef THREAD
#if defined(HAVE_PTHREAD_INIT)
  pthread_init();			/* Must be called before DBUG_ENTER */
#endif
#if !defined( __WIN__) && !defined(__NETWARE__)
  sigfillset(&my_signals);		/* signals blocked by mf_brkhant */
#endif
#endif /* THREAD */
  {
    DBUG_ENTER("my_init");
    DBUG_PROCESS((char*) (my_progname ? my_progname : "unknown"));
    if (!home_dir)
    {					/* Don't initialize twice */
      my_win_init();
      if ((home_dir=getenv("HOME")) != 0)
	home_dir=intern_filename(home_dir_buff,home_dir);
#ifndef VMS
      /* Default creation of new files */
      if ((str=getenv("UMASK")) != 0)
	my_umask=(int) (atoi_octal(str) | 0600);
	/* Default creation of new dir's */
      if ((str=getenv("UMASK_DIR")) != 0)
	my_umask_dir=(int) (atoi_octal(str) | 0700);
#endif
#ifdef VMS
      init_ctype();			/* Stupid linker don't link _ctype.c */
#endif
      DBUG_PRINT("exit",("home: '%s'",home_dir));
    }
#ifdef __WIN__
    win32_init_tcp_ip();
#endif
    DBUG_RETURN(0);
  }
} /* my_init */
Example #3
0
/**
  Initialize my_sys functions, resources and variables

  @return Initialization result
    @retval 0 Success
    @retval 1 Error. Couldn't initialize environment
*/
my_bool my_init(void)
{
  char *str;

  if (my_init_done)
    return 0;

  my_init_done= 1;

  mysys_usage_id++;
  my_umask= 0660;                       /* Default umask for new files */
  my_umask_dir= 0700;                   /* Default umask for new directories */

  /* Default creation of new files */
  if ((str= getenv("UMASK")) != 0)
    my_umask= (int) (atoi_octal(str) | 0600);
  /* Default creation of new dir's */
  if ((str= getenv("UMASK_DIR")) != 0)
    my_umask_dir= (int) (atoi_octal(str) | 0700);

  init_glob_errs();

  instrumented_stdin.m_file= stdin;
  instrumented_stdin.m_psi= NULL;       /* not yet instrumented */
  mysql_stdin= & instrumented_stdin;

  if (my_thread_global_init())
    return 1;

#if defined(SAFE_MUTEX)
  safe_mutex_global_init();		/* Must be called early */
#endif

#if defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX)
  fastmutex_global_init();              /* Must be called early */
#endif

#if defined(HAVE_PTHREAD_INIT)
  pthread_init();			/* Must be called before DBUG_ENTER */
#endif

  /* $HOME is needed early to parse configuration files located in ~/ */
  if ((home_dir= getenv("HOME")) != 0)
    home_dir= intern_filename(home_dir_buff, home_dir);

  {
    DBUG_ENTER("my_init");
    DBUG_PROCESS((char*) (my_progname ? my_progname : "unknown"));
    my_win_init();
    DBUG_PRINT("exit", ("home: '%s'", home_dir));
#ifdef __WIN__
    win32_init_tcp_ip();
#endif
    DBUG_RETURN(0);
  }
} /* my_init */
Example #4
0
/**
  Initialize my_sys functions, resources and variables

  @return Initialization result
    @retval 0 Success
    @retval 1 Error. Couldn't initialize environment
*/
my_bool my_init(void)
{
  char *str;

  if (my_init_done)
    return 0;

  my_init_done= 1;

  mysys_usage_id++;
  my_umask= 0660;                       /* Default umask for new files */
  my_umask_dir= 0700;                   /* Default umask for new directories */
  my_global_flags= 0;

  /* Default creation of new files */
  if ((str= getenv("UMASK")) != 0)
    my_umask= (int) (atoi_octal(str) | 0600);
  /* Default creation of new dir's */
  if ((str= getenv("UMASK_DIR")) != 0)
    my_umask_dir= (int) (atoi_octal(str) | 0700);

  init_glob_errs();

  instrumented_stdin.m_file= stdin;
  instrumented_stdin.m_psi= NULL;       /* not yet instrumented */
  mysql_stdin= & instrumented_stdin;

  my_progname_short= "unknown";
  if (my_progname)
    my_progname_short= my_progname + dirname_length(my_progname);

  /* Initalize our mutex handling */
  my_mutex_init();

  if (my_thread_global_init())
    return 1;

  /* $HOME is needed early to parse configuration files located in ~/ */
  if ((home_dir= getenv("HOME")) != 0)
    home_dir= intern_filename(home_dir_buff, home_dir);

  {
    DBUG_ENTER("my_init");
    DBUG_PROCESS((char*) (my_progname ? my_progname : "unknown"));
    my_time_init();
    my_win_init();
    DBUG_PRINT("exit", ("home: '%s'", home_dir));
#ifdef __WIN__
    win32_init_tcp_ip();
#endif
    DBUG_RETURN(0);
  }
} /* my_init */
Example #5
0
char * my_path(char * to, const char *progname,
               const char *own_pathname_part)
{
  char *start, *end, *prog;
  size_t to_length;
  DBUG_ENTER("my_path");

  start=to;					/* Return this */
  if (progname && (dirname_part(to, progname, &to_length) ||
		   find_file_in_path(to,progname) ||
		   ((prog=getenv("_")) != 0 &&
                    dirname_part(to, prog, &to_length))))
  {
    (void) intern_filename(to,to);
    if (!test_if_hard_path(to))
    {
      if (!my_getwd(curr_dir,FN_REFLEN,MYF(0)))
	bchange((uchar*) to, 0, (uchar*) curr_dir, strlen(curr_dir), strlen(to)+1);
    }
  }
  else
  {
    if ((end = getenv("MY_BASEDIR_VERSION")) == 0 &&
	(end = getenv("MY_BASEDIR")) == 0)
    {
#ifdef DEFAULT_BASEDIR
      end= (char*) DEFAULT_BASEDIR;
#else
      end= (char*) "/my/";
#endif
    }
    (void) intern_filename(to,end);
    to=strend(to);
    if (to != start && to[-1] != FN_LIBCHAR)
      *to++ = FN_LIBCHAR;
    (void) strmov(to,own_pathname_part);
  }
  DBUG_PRINT("exit",("to: '%s'",start));
  DBUG_RETURN(start);
} /* my_path */
Example #6
0
void my_init(void)
{
    my_string str;
    if (my_init_done)
        return;
    my_init_done=1;
#if defined(THREAD) && defined(SAFE_MUTEX)
    safe_mutex_global_init();		/* Must be called early */
#endif
    netware_init();
#ifdef THREAD
#if defined(HAVE_PTHREAD_INIT)
    pthread_init();			/* Must be called before DBUG_ENTER */
#endif
    my_thread_global_init();
#if !defined( __WIN__) && !defined(OS2) && !defined(__NETWARE__)
    sigfillset(&my_signals);		/* signals blocked by mf_brkhant */
#endif
#endif /* THREAD */
#ifdef UNIXWARE_7
    (void) isatty(0);			/* Go around connect() bug in UW7 */
#endif
    {
        DBUG_ENTER("my_init");
        DBUG_PROCESS(my_progname ? my_progname : (char*) "unknown");
        if (!home_dir)
        {   /* Don't initialize twice */
            my_win_init();
            if ((home_dir=getenv("HOME")) != 0)
                home_dir=intern_filename(home_dir_buff,home_dir);
#ifndef VMS
            /* Default creation of new files */
            if ((str=getenv("UMASK")) != 0)
                my_umask=(int) (atoi_octal(str) | 0600);
            /* Default creation of new dir's */
            if ((str=getenv("UMASK_DIR")) != 0)
                my_umask_dir=(int) (atoi_octal(str) | 0700);
#endif
#ifdef VMS
            init_ctype();			/* Stupid linker don't link _ctype.c */
#endif
            DBUG_PRINT("exit",("home: '%s'",home_dir));
        }
#ifdef __WIN__
        win32_init_tcp_ip();
#endif
        DBUG_VOID_RETURN;
    }
} /* my_init */
Example #7
0
/**
  Perform a limited initialisation of mysys.
  This initialisation is sufficient to:
  - allocate memory,
  - read configuration files,
  - parse command lines arguments.
  To complete the mysys initialisation,
  call my_init().
  @return 0 on success
*/
my_bool my_basic_init(void)
{
  char * str;

  if (my_basic_init_done)
    return 0;
  my_basic_init_done= 1;

  mysys_usage_id++;
  my_umask= 0660;                       /* Default umask for new files */
  my_umask_dir= 0700;                   /* Default umask for new directories */

  /* Default creation of new files */
  if ((str= getenv("UMASK")) != 0)
    my_umask= (int) (atoi_octal(str) | 0600);
  /* Default creation of new dir's */
  if ((str= getenv("UMASK_DIR")) != 0)
    my_umask_dir= (int) (atoi_octal(str) | 0700);

  init_glob_errs();

  instrumented_stdin.m_file= stdin;
  instrumented_stdin.m_psi= NULL;       /* not yet instrumented */
  mysql_stdin= & instrumented_stdin;

  if (my_thread_global_init())
    return 1;

#if defined(SAFE_MUTEX)
  safe_mutex_global_init();		/* Must be called early */
#endif

#if defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX)
  fastmutex_global_init();              /* Must be called early */
#endif

#if defined(HAVE_PTHREAD_INIT)
  pthread_init();			/* Must be called before DBUG_ENTER */
#endif
  if (my_thread_basic_global_init())
    return 1;

  /* $HOME is needed early to parse configuration files located in ~/ */
  if ((home_dir= getenv("HOME")) != 0)
    home_dir= intern_filename(home_dir_buff, home_dir);

  return 0;
}
Example #8
0
int my_getwd(my_string buf, uint size, myf MyFlags)
{
  my_string pos;
  DBUG_ENTER("my_getwd");
  DBUG_PRINT("my",("buf: 0x%lx  size: %d  MyFlags %d", buf,size,MyFlags));

#if ! defined(MSDOS)
  if (curr_dir[0])				/* Current pos is saved here */
    VOID(strmake(buf,&curr_dir[0],size-1));
  else
#endif
  {
#if defined(HAVE_GETCWD)
    if (!getcwd(buf,size-2) && MyFlags & MY_WME)
    {
      my_errno=errno;
      my_error(EE_GETWD,MYF(ME_BELL+ME_WAITTANG),errno);
      return(-1);
    }
#elif defined(HAVE_GETWD)
    {
      char pathname[MAXPATHLEN];
      getwd(pathname);
      strmake(buf,pathname,size-1);
    }
#elif defined(VMS)
    if (!getcwd(buf,size-2,1) && MyFlags & MY_WME)
    {
      my_errno=errno;
      my_error(EE_GETWD,MYF(ME_BELL+ME_WAITTANG),errno);
      return(-1);
    }
    intern_filename(buf,buf);
#else
#error "No way to get current directory"
#endif
    if (*((pos=strend(buf))-1) != FN_LIBCHAR)  /* End with FN_LIBCHAR */
    {
      pos[0]= FN_LIBCHAR;
      pos[1]=0;
    }
    (void) strmake(&curr_dir[0],buf,(size_s) (FN_REFLEN-1));
  }
  DBUG_RETURN(0);
} /* my_getwd */
Example #9
0
uint unpack_dirname(my_string to, const char *from)
{
  uint length,h_length;
  char buff[FN_REFLEN+1+4],*suffix,*tilde_expansion;
  DBUG_ENTER("unpack_dirname");

  (void) intern_filename(buff,from);		/* Change to intern name */
  length= (uint) strlen(buff);			/* Fix that '/' is last */
  if (length &&
#ifdef FN_DEVCHAR
      buff[length-1] != FN_DEVCHAR &&
#endif
      buff[length-1] != FN_LIBCHAR && buff[length-1] != '/')
  {
    buff[length]=FN_LIBCHAR;
    buff[length+1]= '\0';
  }

  length=cleanup_dirname(buff,buff);
  if (buff[0] == FN_HOMELIB)
  {
    suffix=buff+1; tilde_expansion=expand_tilde(&suffix);
    if (tilde_expansion)
    {
      length-=(uint) (suffix-buff)-1;
      if (length+(h_length= (uint) strlen(tilde_expansion)) <= FN_REFLEN)
      {
	if (tilde_expansion[h_length-1] == FN_LIBCHAR)
	  h_length--;
	if (buff+h_length < suffix)
	  bmove(buff+h_length,suffix,length);
	else
	  bmove_upp(buff+h_length+length,suffix+length,length);
	bmove(buff,tilde_expansion,h_length);
      }
    }
  }
#ifdef USE_SYMDIR
  if (my_use_symdir)
    symdirget(buff);
#endif
  DBUG_RETURN(system_filename(to,buff));	/* Fix for open */
} /* unpack_dirname */
Example #10
0
void pack_dirname(my_string to, const char *from)
{
  int cwd_err;
  uint d_length,length,buff_length;
  my_string start;
  char buff[FN_REFLEN];
  DBUG_ENTER("pack_dirname");

  LINT_INIT(buff_length);
  (void) intern_filename(to,from);		/* Change to intern name */

#ifdef FN_DEVCHAR
  if ((start=strrchr(to,FN_DEVCHAR)) != 0)	/* Skipp device part */
    start++;
  else
#endif
    start=to;

  if (!(cwd_err= my_getwd(buff,FN_REFLEN,MYF(0))))
  {
    buff_length= (uint) strlen(buff);
    d_length=(uint) (start-to);
    if ((start == to ||
	 (buff_length == d_length && !bcmp(buff,start,d_length))) &&
	*start != FN_LIBCHAR && *start)
    {						/* Put current dir before */
      bchange(to,d_length,buff,buff_length,(uint) strlen(to)+1);
    }
  }

  if ((d_length= cleanup_dirname(to,to)) != 0)
  {
    length=0;
    if (home_dir)
    {
      length= (uint) strlen(home_dir);
      if (home_dir[length-1] == FN_LIBCHAR)
	length--;				/* Don't test last '/' */
    }
    if (length > 1 && length < d_length)
    {						/* test if /xx/yy -> ~/yy */
      if (bcmp(to,home_dir,length) == 0 && to[length] == FN_LIBCHAR)
      {
	to[0]=FN_HOMELIB;			/* Filename begins with ~ */
	(void) strmov_overlapp(to+1,to+length);
      }
    }
    if (! cwd_err)
    {						/* Test if cwd is ~/... */
      if (length > 1 && length < buff_length)
      {
	if (bcmp(buff,home_dir,length) == 0 && buff[length] == FN_LIBCHAR)
	{
	  buff[0]=FN_HOMELIB;
	  (void) strmov_overlapp(buff+1,buff+length);
	}
      }
      if (is_prefix(to,buff))
      {
	length= (uint) strlen(buff);
	if (to[length])
	  (void) strmov_overlapp(to,to+length);	/* Remove everything before */
	else
	{
	  to[0]= FN_CURLIB;			/* Put ./ instead of cwd */
	  to[1]= FN_LIBCHAR;
	  to[2]= '\0';
	}
      }
    }
  }
  DBUG_PRINT("exit",("to: '%s'",to));
  DBUG_VOID_RETURN;
} /* pack_dirname */