示例#1
0
const char * ndbGetVersionString(Uint32 version, Uint32 mysql_version,
                                 const char * status,
                                 char *buf, unsigned sz)
{
    char tmp[NDB_VERSION_STRING_BUF_SZ];
    if (status && status[0] != 0)
        basestring_snprintf(tmp, sizeof(tmp), "%s", status);
    else
        tmp[0] = 0;

    if (mysql_version)
    {
        basestring_snprintf(buf, sz, "mysql-%d.%d.%d ndb-%d.%d.%d%s",
                            getMajor(mysql_version),
                            getMinor(mysql_version),
                            getBuild(mysql_version),
                            getMajor(version),
                            getMinor(version),
                            getBuild(version),
                            tmp);
    }
    else
    {
        basestring_snprintf(buf, sz, "ndb-%d.%d.%d%s",
                            getMajor(version),
                            getMinor(version),
                            getBuild(version),
                            tmp);
    }
    return buf;
}
示例#2
0
static void
build_tree(const char* path)
{
    char tmp[PATH_MAX];
    CHECK(NdbDir::create(path));

    // Create files in path/
    for (int i = 8; i < 14; i++) {
        basestring_snprintf(tmp, sizeof(tmp), "%s%sfile%d", path, DIR_SEPARATOR, i);
        fclose(fopen(tmp, "w"));
    }

    // Create directories
    for (int i = 8; i < 14; i++) {
        basestring_snprintf(tmp, sizeof(tmp), "%s%sdir%d", path, DIR_SEPARATOR, i);
        CHECK(NdbDir::create(tmp));

        // Create files in dir
        for (int j = 0; j < 6; j++) {
            basestring_snprintf(tmp, sizeof(tmp), "%s%sdir%d%sfile%d",
                                path, DIR_SEPARATOR, i, DIR_SEPARATOR, j);
            fclose(fopen(tmp, "w"));
        }
    }

#ifndef _WIN32
    // Symlink the last file created to path/symlink
    char tmp2[PATH_MAX];
    basestring_snprintf(tmp2, sizeof(tmp2), "%s%ssymlink", path, DIR_SEPARATOR);
    CHECK(symlink(tmp, tmp2) == 0);
#endif
}
示例#3
0
static
char *get_prefix_buf(int len, int node_id)
{
  char tmp_buf[sizeof("ndb_pid#############")+1];
  char *buf;
  if (node_id > 0)
    basestring_snprintf(tmp_buf, sizeof(tmp_buf), "ndb_%u", node_id);
  else
    basestring_snprintf(tmp_buf, sizeof(tmp_buf), "ndb_pid%u", getpid());
  tmp_buf[sizeof(tmp_buf)-1]= 0;

  buf= NdbConfig_AllocHomePath(len+strlen(tmp_buf));
  strcat(buf, tmp_buf);
  return buf;
}
示例#4
0
char*
NdbConfig_ClusterLogFileName(int node_id){
  char *buf= get_prefix_buf(PATH_MAX, node_id);
  int len= strlen(buf);
  basestring_snprintf(buf+len, PATH_MAX, "_cluster.log");
  return buf;
}
示例#5
0
char*
NdbConfig_PidFileName(int node_id){
  char *buf= get_prefix_buf(PATH_MAX, node_id);
  int len= strlen(buf);
  basestring_snprintf(buf+len, PATH_MAX, ".pid");
  return buf;
}
示例#6
0
char*
NdbConfig_NextTraceFileName(int node_id){
  char *buf= get_prefix_buf(PATH_MAX, node_id);
  int len= strlen(buf);
  basestring_snprintf(buf+len, PATH_MAX, "_trace.log.next");
  return buf;
}
示例#7
0
文件: version.c 项目: Coco-wan/git-1
const char * ndbGetVersionString(Uint32 version, const char * status,
                                 char *buf, unsigned sz)
{
  if (status && status[0] != 0)
	  basestring_snprintf(buf, sz,
	     "Version %d.%d.%d (%s)",
	     getMajor(version),
	     getMinor(version),
	     getBuild(version),
	     status);
  else
    basestring_snprintf(buf, sz,
	     "Version %d.%d.%d",
	     getMajor(version),
	     getMinor(version),
	     getBuild(version));
  return buf;
}
示例#8
0
static char* 
NdbConfig_AllocHomePath(int _len)
{
  int path_len;
  const char *path= NdbConfig_get_path(&path_len);
  int len= _len+path_len;
  char *buf= NdbMem_Allocate(len);
  basestring_snprintf(buf, len, "%s%s", path, DIR_SEPARATOR);
  return buf;
}
示例#9
0
char* 
NdbConfig_NdbCfgName(int with_ndb_home){
  char *buf;
  int len= 0;

  if (with_ndb_home) {
    buf= NdbConfig_AllocHomePath(PATH_MAX);
    len= strlen(buf);
  } else
    buf= NdbMem_Allocate(PATH_MAX);
  basestring_snprintf(buf+len, PATH_MAX, "Ndb.cfg");
  return buf;
}
示例#10
0
 int open(const char* path) {
     char path_buf[PATH_MAX+2];
     m_first = true;
     basestring_snprintf(path_buf, sizeof(path_buf), "%s\\*", path);
     m_find_handle = FindFirstFile(path_buf, &m_find_data);
     if(m_find_handle == INVALID_HANDLE_VALUE)
     {
         if (GetLastError() == ERROR_FILE_NOT_FOUND)
             m_first= false; // Will do a seek in 'next_file' and return NULL
         else
             return -1;
     }
     return 0;
 }
示例#11
0
    bool is_regular_file(struct dirent* dp) const {
#ifdef _DIRENT_HAVE_D_TYPE
        /*
          Using dirent's d_type field to determine if
          it's a regular file
        */
        if(dp->d_type != DT_UNKNOWN)
            return (dp->d_type == DT_REG);
#endif
        /* Using stat to read more info about the file */
        basestring_snprintf(m_buf, PATH_MAX,
                            "%s/%s", m_path, dp->d_name);

        struct stat buf;
        if (lstat(m_buf, &buf)) // Use lstat to not follow symlinks
            return false; // 'stat' failed

        return S_ISREG(buf.st_mode);

    }
示例#12
0
void
arg_printusage (struct getargs *args,
		size_t num_args,
		const char *progname,
		const char *extra_string)
{
    unsigned int i;
    size_t max_len = 0;
    char buf[128];
    int col = 0, columns;

#ifdef HAVE___PROGNAME
    if (progname == NULL)
	progname = __progname;
#endif
    if (progname == NULL)
	progname = "";

#ifdef GETARGMANDOC
    if(getenv("GETARGMANDOC")){
	mandoc_template(args, num_args, progname, extra_string);
	return;
    }
#endif

    columns = 80; /* Always assume that the window is 80 chars wide */
    col = 0;
    col += fprintf (stderr, "Usage: %s", progname);
    for (i = 0; i < num_args; ++i) {
	size_t len = 0;

	if (args[i].long_name) {
	    buf[0] = '\0';
	    strlcat(buf, "[--", sizeof(buf));
	    len += 2;
	    if(args[i].type == arg_negative_flag) {
		strlcat(buf, "no-", sizeof(buf));
		len += 3;
	    }
	    strlcat(buf, args[i].long_name, sizeof(buf));
	    len += strlen(args[i].long_name);
	    len += print_arg(buf + strlen(buf), sizeof(buf) - strlen(buf), 
			     0, 1, &args[i]);
	    strlcat(buf, "]", sizeof(buf));
	    if(args[i].type == arg_strings)
		strlcat(buf, "...", sizeof(buf));
	    col = check_column(stderr, col, (int)strlen(buf) + 1, columns);
	    col += fprintf(stderr, " %s", buf);
	}
	if (args[i].short_name) {
	    basestring_snprintf(buf, sizeof(buf), "[-%c", args[i].short_name);
	    len += 2;
	    len += print_arg(buf + strlen(buf), sizeof(buf) - strlen(buf), 
			     0, 0, &args[i]);
	    strlcat(buf, "]", sizeof(buf));
	    if(args[i].type == arg_strings)
		strlcat(buf, "...", sizeof(buf));
	    col = check_column(stderr, col, (int)strlen(buf) + 1, columns);
	    col += fprintf(stderr, " %s", buf);
	}
	if (args[i].long_name && args[i].short_name)
	    len += 2; /* ", " */
	max_len = max(max_len, len);
    }
    if (extra_string) {
	col = check_column(stderr, col, (int)strlen(extra_string) + 1, columns);
	fprintf (stderr, " %s\n", extra_string);
    } else
	fprintf (stderr, "\n");
    for (i = 0; i < num_args; ++i) {
	if (args[i].help) {
	    size_t count = 0;

	    if (args[i].short_name) {
		count += fprintf (stderr, "-%c", args[i].short_name);
		print_arg (buf, sizeof(buf), 0, 0, &args[i]);
		count += fprintf(stderr, "%s", buf);
	    }
	    if (args[i].short_name && args[i].long_name)
		count += fprintf (stderr, ", ");
	    if (args[i].long_name) {
		count += fprintf (stderr, "--");
		if (args[i].type == arg_negative_flag)
		    count += fprintf (stderr, "no-");
		count += fprintf (stderr, "%s", args[i].long_name);
		print_arg (buf, sizeof(buf), 0, 1, &args[i]);
		count += fprintf(stderr, "%s", buf);
	    }
	    while(count++ <= max_len)
		putc (' ', stderr);
	    fprintf (stderr, "%s\n", args[i].help);
	}
    }
}
示例#13
0
bool
NdbDir::remove_recursive(const char* dir, bool only_contents)
{
    char path[PATH_MAX];
    if (basestring_snprintf(path, sizeof(path),
                            "%s%s", dir, DIR_SEPARATOR) < 0) {
        fprintf(stderr, "Too long path to remove: '%s'\n", dir);
        return false;
    }
    int start_len = strlen(path);

    const char* name;
    NdbDir::Iterator iter;
loop:
    {
        if (iter.open(path) != 0)
        {
            fprintf(stderr, "Failed to open iterator for '%s'\n",
                    path);
            return false;
        }

        while ((name = iter.next_entry()) != NULL)
        {
            if ((strcmp(".", name) == 0) || (strcmp("..", name) == 0))
                continue;

            int end_len, len = strlen(path);
            if ((end_len = basestring_snprintf(path + len, sizeof(path) - len,
                                               "%s", name)) < 0)
            {
                fprintf(stderr, "Too long path detected: '%s'+'%s'\n",
                        path, name);
                return false;
            }

            if (unlink(path) == 0 || NdbDir::remove(path) == true)
            {
                path[len] = 0;
                continue;
            }

            iter.close();

            // Append ending slash to the string
            int pos = len + end_len;
            if (basestring_snprintf(path + pos, sizeof(path) - pos,
                                    "%s", DIR_SEPARATOR) < 0)
            {
                fprintf(stderr, "Too long path detected: '%s'+'%s'\n",
                        path, DIR_SEPARATOR);
                return false;
            }

            goto loop;
        }
        iter.close();

        int len = strlen(path);
        path[len - 1] = 0; // remove ending slash

        char * prev_slash = strrchr(path, IF_WIN('\\', '/'));
        if (len > start_len && prev_slash)
        {
            // Not done yet, step up one dir level
            assert(prev_slash > path && prev_slash < path + sizeof(path));
            prev_slash[1] = 0;
            goto loop;
        }
    }

    if (only_contents == false && NdbDir::remove(dir) == false)
    {
        fprintf(stderr,
                "Failed to remove directory '%s', error: %d\n",
                dir, errno);
        return false;
    }

    return true;
}