Exemplo n.º 1
0
int
pathmake3(char *dst, ...)
{
  va_list  args;
  char    *p;
  path_t   temp;

  temp[0] = 0;
  va_start(args, dst);
  while ((p = va_arg(args, char*))) {
    if (p[0] == '/' && p[1] == 0) {
      strmcat(temp, PATH_SEP, PATH_MAX);
    } else {
      strmcat(temp, p, PATH_MAX);
    }
  }
  va_end(args);
  
  dst[0] = 0;
  if (!os_IsAbsolutePath(temp)) {
    os_rGetWorkingDir(dst, PATH_MAX, 1);
    pathcat(dst, PATH_SEP);
  }
  pathcat(dst, temp);
  return strlen(dst);
}
Exemplo n.º 2
0
static int cow_readdir(const char* orig_path, void *buf,
                       fuse_fill_dir_t filler,
                       off_t offset, struct fuse_file_info *fi)
{
  DIR *dp;
  struct dirent *de;

  (void) offset;
  (void) fi;

  char* path = pathcat(the_config.cow_dir, orig_path);
  dp = opendir(path);
  free(path);

  if (dp == NULL)
    return -errno;

  while ((de = readdir(dp)) != NULL) {
    struct stat st;
    memset(&st, 0, sizeof(st));
    st.st_ino = de->d_ino;
    st.st_mode = de->d_type << 12;
    if (filler(buf, de->d_name, &st, 0))
      break;
  }

  closedir(dp);
  return 0;
}
Exemplo n.º 3
0
/**
 * reads the mime file and retrieves the mime for a specific resource
 */
int mime_read(conf_s conf, const char *file, content_type ctype) {
    FILE *fd;
    char fbuf[PATH_MAX], buf[WCONF_MAX_LINE_BUF];

    const char *word = fext(file);
    size_t len = strlen(word);
    size_t pos = 0;

    pathcat(conf.document_root, conf.mime, fbuf);

    if ((fd = fopen(fbuf, "r")) == 0) return -1;

    while(fgets(buf, WCONF_MAX_LINE_BUF, fd) != 0 && *ctype == 0) {
        // Remove newline
        remove_newline(buf);

        if (buf[0] != '#') {
            pos = strnmime(word, len, buf);
            if (pos) {
                strncpy(ctype, buf, pos);
            }
        }
    }

    fclose(fd);

    if (pos == 0)
        strncpy(ctype, "text/plain", 11);

    return 1;
}
Exemplo n.º 4
0
static char *
cvs_dir(char *working_directory)
{
    char temp[MAXPATHLEN];
    abspath(pathcat(temp, working_directory, "CVS"));
    return txtalloc(temp);
}
Exemplo n.º 5
0
static int cow_link(const char *orig_from, const char *orig_to)
{
  int res;

  char* from = pathcat(the_config.cow_dir, orig_from);
  char* to = pathcat(the_config.cow_dir, orig_to);

  res = link(from, to);

  free(from);
  free(to);

  if (res == -1)
    return -errno;

  return 0;
}
Exemplo n.º 6
0
void list_dir(void *arg) {
	terminal_clear();
	printf("%s\n", path);
	printf("%s", arg);
	
	int files, fd, i, j, k;
	
	for(i = 0; i < 8; i++) {
		dir[i][0] = 0;
	}
	
	uint8_t stat;
	struct FATDirList list[8];
	char *buf, *tmp;
	for(files = 0; (i = fat_dirlist(path, list, 8, files)); files += i) {
		for (j = i - 1; j >= 0; j--) {
			if(list[j].filename[0]) {
				stat = list[j].attrib;
				
				//skip volume labels
				if(stat & 0x8)
					continue;
				
				if(list[j].filename[0] == '.')
					continue;
				
				buf = dir[j];
				
				for(k = 5; k != ~0; k--) {
					if(stat & (0x1 << k))
						*buf++ = attribs[k];
					else
						*buf++ = '-';
				}
				if(stat & 0x10) {
					*buf++ = '\t';
					*buf++ = '\t';
				} else {
					pathcat((char *) pathbuf, path, list[j].filename);
					fd = fat_open(pathbuf, O_RDONLY);
					*buf++ = '\t';
					//print_filesize(fat_fsize(fd));
					*buf++ = '0';
					*buf++ = '\t';
					fat_close(fd);
				}
				tmp = list[j].filename;
				
				while(*tmp) {
					*buf++ = *tmp++;
				}
				*buf = 0;
			}
		}
	}
}
Exemplo n.º 7
0
char *
tempnam(const char *head, const char *tail)
{
    char temp[NFILEN];
    char leaf[NFILEN];

    return mktemp(strmalloc(pathcat(temp,
				    head,
				    strcat(strcpy(leaf, tail),
					   "XXXXXX"))));
}
Exemplo n.º 8
0
static void maybe_copy(const char* path) {
  char* src_path = pathcat(the_config.src_dir, path);
  char* cow_path = pathcat(the_config.cow_dir, path);

  struct stat src_st, cow_st;
  int ret;

  ret = stat(src_path, &src_st);
  if (ret < 0) { goto end; }

  ret = stat(cow_path, &cow_st);
  if (ret < 0) { goto end; }

  if (src_st.st_ino == cow_st.st_ino) {
    copy_file(src_path, cow_path);
  }

end:
  free(src_path);
  free(cow_path);
}
Exemplo n.º 9
0
void
cvslast(const char *working,	/* working directory (absolute) */
	const char *path,	/* pathname to check (may be relative) */
	const char **vers_,
	time_t * date_,
	const char **lock_)
{
    char temp[MAXPATHLEN];

    abspath(pathcat(temp, working, path));
    tryCVS(temp, vers_, date_, lock_);
}
Exemplo n.º 10
0
XzeroDaemon::XzeroDaemon(int argc, char *argv[]) :
    state_(XzeroState::Inactive),
    argc_(argc),
    argv_(argv),
    showGreeter_(false),
    configfile_(pathcat(SYSCONFDIR, "x0d.conf")),
    pidfile_(),
    user_(),
    group_(),
    logTarget_("file"),
    logFile_(pathcat(LOGDIR, "x0d.log")),
    logLevel_(Severity::info),
    instant_(),
    documentRoot_(),
    nofork_(false),
    systemd_(getppid() == 1 && sd_booted()),
    doguard_(false),
    dumpIR_(false),
    optimizationLevel_(2),
    server_(nullptr),
    evFlags_(0),
    eventHandler_(nullptr),
    pluginDirectory_(PLUGINDIR),
    plugins_(),
    pluginLibraries_(),
    core_(nullptr),
    components_(),
    unit_(nullptr),
    runner_(nullptr),
    setupApi_(),
    mainApi_()
{
    x0::FlowRunner::initialize();

    runner_ = new FlowRunner(this);
    runner_->setErrorHandler(std::bind(&wrap_log_error, this, "codegen", std::placeholders::_1));

    instance_ = this;
}
Exemplo n.º 11
0
static int cow_rmdir(const char* orig_path)
{
  int res;

  char* path = pathcat(the_config.cow_dir, orig_path);
  res = rmdir(path);
  free(path);

  if (res == -1)
    return -errno;

  return 0;
}
Exemplo n.º 12
0
static int cow_chmod(const char* orig_path, mode_t mode)
{
  int res;

  char* path = pathcat(the_config.cow_dir, orig_path);
  res = chmod(path, mode);
  free(path);

  if (res == -1)
    return -errno;

  return 0;
}
Exemplo n.º 13
0
static int cow_access(const char *orig_path, int mask)
{
  int res;

  char* path = pathcat(the_config.cow_dir, orig_path);
  res = access(path, mask);
  free(path);

  if (res == -1)
    return -errno;

  return 0;
}
Exemplo n.º 14
0
static int cow_getattr(const char *orig_path, struct stat *stbuf)
{
  int res;

  char* path = pathcat(the_config.cow_dir, orig_path);
  res = lstat(path, stbuf);
  free(path);

  if (res == -1)
    return -errno;

  return 0;
}
Exemplo n.º 15
0
static int cow_chown(const char* orig_path, uid_t uid, gid_t gid)
{
  int res;

  char* path = pathcat(the_config.cow_dir, orig_path);
  res = lchown(path, uid, gid);
  free(path);

  if (res == -1)
    return -errno;

  return 0;
}
Exemplo n.º 16
0
void
fDoDel (
    char	    *name,
    struct findType *pBuf,
    void	    *dummy
    )
{
    char *p;

    //
    // if it is a file, attempt to delete it
    //
    if (!TESTFLAG(pBuf->fbuf.dwFileAttributes, FILE_ATTRIBUTE_DIRECTORY)) {

        //
        // if file is read-only, make it writable
        //
        if (TESTFLAG(pBuf->fbuf.dwFileAttributes, FILE_ATTRIBUTE_READONLY)) {
            if(!SetFileAttributes(name, pBuf->fbuf.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY)) {
                return;
            }
        }
        _unlink (name);

    } else if( strcmp( pBuf->fbuf.cFileName, "." ) &&
               strcmp( pBuf->fbuf.cFileName, ".." ) ) {

        //
        // if directory is read-only, make it writable
        //
        if (TESTFLAG(pBuf->fbuf.dwFileAttributes, FILE_ATTRIBUTE_READONLY)) {
            if(!SetFileAttributes(name, pBuf->fbuf.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY)) {
                return;
            }
        }

        //
        // clear out subdir first
        //
        p = strend( name );
        pathcat( name, "*.*" );
        forfile(name, FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_DIRECTORY, fDoDel, NULL);
        //if (!forfile(name, FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_DIRECTORY, fDoDel, NULL)) {
        //    return;
        //}
        *p = 0;
        _rmdir (name);
    }

    dummy;
}
Exemplo n.º 17
0
XzeroDaemon::XzeroDaemon(int argc, char *argv[]) :
	state_(XzeroState::Inactive),
	argc_(argc),
	argv_(argv),
	showGreeter_(false),
	configfile_(pathcat(SYSCONFDIR, "x0d.conf")),
	pidfile_(),
	user_(),
	group_(),
	logTarget_("file"),
	logFile_(pathcat(LOGDIR, "x0d.log")),
	logLevel_(Severity::info),
	instant_(),
	documentRoot_(),
	nofork_(false),
	systemd_(getppid() == 1 && sd_booted()),
	doguard_(false),
    dumpAST_(false),
	dumpIR_(false),
    dumpTargetCode_(false),
	optimizationLevel_(1),
	server_(nullptr),
	evFlags_(0),
	eventHandler_(nullptr),
	pluginDirectory_(PLUGINDIR),
	plugins_(),
	pluginLibraries_(),
	core_(nullptr),
	components_(),
	unit_(),
	program_(),
    main_(nullptr),
	setupApi_(),
	mainApi_()
{
    TRACE(2, "initializing");
	instance_ = this;
}
Exemplo n.º 18
0
static int cow_readlink(const char* orig_path, char *buf, size_t size)
{
  int res;

  // XXX/bowei -- needs adjusting
  char* path = pathcat(the_config.cow_dir, orig_path);
  res = readlink(path, buf, size - 1);
  free(path);

  if (res == -1)
    return -errno;

  buf[res] = '\0';
  return 0;
}
Exemplo n.º 19
0
int command_remove_tag(int argc, char **argv, int optind, int flags) {
  const char *filename = argv[argc-1];
  char *str, *nstr, *p, *q;
  const char *d;
  int i;

  for(i = optind; i < argc; ++i) {
    check_access_flags(argv[i], F_OK | R_OK | W_OK, 1);
    str = get_basename((char*)argv[i]);
    if((nstr = strip_tag((const char*) str, crcregex_stripper)) == NULL) {
      log_failure(argv[i], "no hexstring found");
      return EXIT_FAILURE;
    }
    d = (const char*) dirname((char*)argv[i]);
    p = pathcat(d, (const char*)str);
    q = pathcat(d, (const char*)nstr);
    if(rename((const char*) p, (const char*) q) != 0)
      LERROR(EXIT_FAILURE, errno, "rename() failed");
    free(p);
    free(q);
    free(nstr);
  }
  return EXIT_SUCCESS;
}
Exemplo n.º 20
0
static int cow_open(const char* orig_path, struct fuse_file_info *fi)
{
  int res;

  maybe_copy(orig_path);

  char* path = pathcat(the_config.cow_dir, orig_path);
  res = open(path, fi->flags);
  free(path);

  if (res == -1)
    return -errno;

  close(res);
  return 0;
}
Exemplo n.º 21
0
static int cow_truncate(const char* orig_path, off_t size)
{
  int res;

  maybe_copy(orig_path);

  char* path = pathcat(the_config.cow_dir, orig_path);
  res = truncate(path, size);
  // XXX
  free(path);

  if (res == -1)
    return -errno;

  return 0;
}
Exemplo n.º 22
0
/* iterative routine takes args as pbuf, pfile */
flagType fPFind (char *p, va_list ap)
{
    //
    //  pArg is a pointer to an argument list. The first argument is a
    //  pointer to the file name. The second argument is a pointer to
    //  a buffer.
    //
    char    *pa[2];

    pa[1] = (char *)va_arg(ap, PCHAR);
    pa[0] = (char *)va_arg(ap, PCHAR);

    va_end(ap);

    /*  p == dir from env variable expansion or null
     *  pa[1] == file name
     *  pa[0] == buffer for getting p\pa[1] or pa[1] if p null
     */

    strcpy ((char *)pa[0], p);
    pathcat ((char *) pa[0], (char *) pa[1]);

    {
        HANDLE TmpHandle;
        WIN32_FIND_DATA buffer;

        TmpHandle = FindFirstFile((LPSTR)pa[0],&buffer);

        if (TmpHandle == INVALID_HANDLE_VALUE) {
            return FALSE;
        }

        FindClose(TmpHandle);

        if ((buffer.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
            return FALSE;
        }

        //struct stat sbuf;
        //if (stat ((char *)pa[0], &sbuf) == -1)
        //    return FALSE;
        //if ((sbuf.st_mode & S_IFREG) == 0)
        //    return FALSE;
    }
    pname ((char *) pa[0]);
    return TRUE;
}
Exemplo n.º 23
0
inline void PdUI::add_elem(ui_elem_type_t type, const char *label, float *zone)
{
  ui_elem_t *elems1 = (ui_elem_t*)realloc(elems, (nelems+1)*sizeof(ui_elem_t));
  if (elems1)
    elems = elems1;
  else
    return;
  std::string s = pathcat(path, mangle(name, level, label));
  elems[nelems].type = type;
  elems[nelems].label = strdup(s.c_str());
  elems[nelems].zone = zone;
  elems[nelems].init = 0.0;
  elems[nelems].min = 0.0;
  elems[nelems].max = 1.0;
  elems[nelems].step = 1.0;
  nelems++;
}
Exemplo n.º 24
0
static int
WALK_FUNC(scan_tree)
{
    char tmp[BUFSIZ];
    char *s = pathcat(tmp, path, name);
    Stat_t sb;

    if (RCS_DEBUG)
	PRINTF("++ %s%sscan (%s, %s, %s%d)\n",
	       R_opt ? "R " : "",
	       L_opt ? "L " : "",
	       path, name, (sp == 0) ? "no-stat, " : "", level);

    if (!quiet || n_opt)
	track_wd(path);

    if (sp == 0) {
	if (R_opt && (level > 0)) {
	    Ignore(name, " (no such file)");
	}
    } else if (isDIR(sp->st_mode)) {
	abspath(s);		/* get rid of "." and ".." names */
	if (ignore_dir(s))
	    readable = -1;
	else if (sameleaf(s, rcs_dir(NULL, NULL))) {
	    if (R_opt) {
		(void) walktree(strcpy(user_wd, path),
				name, scan_archive, "r", level);
	    }
	    readable = -1;
	} else {
#ifdef	S_IFLNK
	    if (!L_opt
		&& (lstat(s, &sb) < 0 || isLINK(sb.st_mode))) {
		Ignore(name, " (is a link)");
		readable = -1;
	    }
#endif
	}
    } else if (!isFILE(sp->st_mode)) {
	Ignore(name, RCS_DEBUG ? " (not a file)" : "");
	readable = -1;
    }
    return (readable);
}
Exemplo n.º 25
0
void config(char* conf, size_t conf_size, const char* argv0)
{
#ifdef _WIN32
	char* slash;

	pathimport(conf, conf_size, argv0);

	slash = strrchr(conf, '/');
	if (slash) {
		slash[1] = 0;
		pathcat(conf, conf_size, PACKAGE ".conf");
	} else {
		pathcpy(conf, conf_size, PACKAGE ".conf");
	}
#else
	(void)argv0;

	pathcpy(conf, conf_size, "/etc/" PACKAGE ".conf");
#endif
}
Exemplo n.º 26
0
void select_file(void *arg) {
	int selected = *((int *) arg);
	char *tmp, *tmp2;
	
	tmp = dir[selected];
	while(*tmp++ != '\t');
	while(*tmp++ != '\t');
	
	pathcat(pathbuf, path, tmp);
	tmp = pathbuf;
	tmp2 = path;
	while((*tmp2++ = *tmp++));
	
	if(dir[selected][1] == 'D') {
		menu_dir.selected = 8;
		menu_execute(&menu_dir);
		tmp = path;
		while(*tmp++);
		while(tmp != path) {
			*tmp = 0;
			if(*tmp == '/') {
				break;
			}
			tmp--;
		}
	} else {
		menu_dir.selected = 0;
		menu_execute(&menu_file);
		
		tmp = path;
		while(*tmp++);
		while(tmp != path) {
			*tmp = 0;
			if(*tmp == '/') {
				break;
			}
			tmp--;
		}
	}
}
Exemplo n.º 27
0
/*ARGSUSED*/
static int
WALK_FUNC(scan_archive)
{
    char tmp[BUFSIZ];

    (void) level;

    if (!strcmp(user_wd, path))	/* account for initial argument */
	return (readable);
    if (!isFILE(sp->st_mode)
	|| !an_archive(name)) {
	Ignore(name, " (not an archive)");
	return (-1);
    }
    if (!strcmp(vcs_file((char *) 0, strcpy(tmp, name), FALSE), name))
	return (readable);

    set_wd(user_wd);
    Checkout(rcs2name(name, FALSE), pathcat(tmp, rcs_dir(NULL, NULL), name));
    set_wd(path);
    return (readable);
}
Exemplo n.º 28
0
static int cow_mknod(const char* orig_path, mode_t mode, dev_t rdev)
{
  int res;

  char* path = pathcat(the_config.cow_dir, orig_path);
  /* On Linux this could just be 'mknod(path, mode, rdev)' but this
     is more portable */
  if (S_ISREG(mode)) {
    res = open(path, O_CREAT | O_EXCL | O_WRONLY, mode);
    if (res >= 0)
      res = close(res);
  } else if (S_ISFIFO(mode))
    res = mkfifo(path, mode);
  else
    res = mknod(path, mode, rdev);

  free(path);

  if (res == -1)
    return -errno;

  return 0;
}
Exemplo n.º 29
0
static int cow_read(const char* orig_path, char *buf,
                    size_t size, off_t offset,
                    struct fuse_file_info *fi)
{
  int fd;
  int res;

  (void) fi;

  char* path = pathcat(the_config.cow_dir, orig_path);
  fd = open(path, O_RDONLY);
  free(path);

  if (fd == -1)
    return -errno;

  res = pread(fd, buf, size, offset);
  if (res == -1)
    res = -errno;

  close(fd);
  return res;
}
Exemplo n.º 30
0
int removedir(const char *path)
{
    DIR *d = opendir(path);
    int r = -1;

    if (d)
    {
        struct dirent *p;
        r = 0;

        while (!r && (p = readdir(d)))
        {
            /* Skip the names "." and ".." as we don't want to recurse on them. */
            if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, ".."))
                continue;

            int r2 = -1;
            struct stat statbuf;
            const char *buf = pathcat(path, p->d_name);
            if (!stat(buf, &statbuf))
            {
                if (S_ISDIR(statbuf.st_mode))
                    r2 = removedir(buf);
                else
                    r2 = unlink(buf);
            }
            free((void *)buf);
            r = r2;
        }
        closedir(d);
    }

    if (!r)
        r = rmdir(path);
    return r;
}