当前位置: 首页>>代码示例>>C++>>正文


C++ dirname函数代码示例

本文整理汇总了C++中dirname函数的典型用法代码示例。如果您正苦于以下问题:C++ dirname函数的具体用法?C++ dirname怎么用?C++ dirname使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了dirname函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main


//.........这里部分代码省略.........
    {   0, "htsp_port2", "Specify extra htsp port",
      OPT_INT, &tvheadend_htsp_port_extra },
    {   0, "useragent",  "Specify User-Agent header for the http client",
      OPT_STR, &opt_user_agent },
    {   0, "xspf",       "Use xspf playlist instead M3U",
      OPT_BOOL, &opt_xspf },

    {   0, NULL,        "Debug Options",           OPT_BOOL, NULL         },
    { 'd', "stderr",    "Enable debug on stderr",  OPT_BOOL, &opt_stderr  },
    { 's', "syslog",    "Enable debug to syslog",  OPT_BOOL, &opt_syslog  },
    { 'l', "logfile",   "Enable debug to file",    OPT_STR,  &opt_logpath },
    {   0, "debug",     "Enable debug subsystems", OPT_STR,  &opt_log_debug },
#if ENABLE_TRACE
    {   0, "trace",     "Enable trace subsystems", OPT_STR,  &opt_log_trace },
#endif
    {   0, "fileline",  "Add file and line numbers to debug", OPT_BOOL, &opt_fileline },
    {   0, "threadid",  "Add the thread ID to debug", OPT_BOOL, &opt_threadid },
    {   0, "uidebug",   "Enable webUI debug (non-minified JS)", OPT_BOOL, &opt_uidebug },
    { 'A', "abort",     "Immediately abort",       OPT_BOOL, &opt_abort   },
    { 'D', "dump",      "Enable coredumps for daemon", OPT_BOOL, &opt_dump },
    {   0, "noacl",     "Disable all access control checks",
      OPT_BOOL, &opt_noacl },
    { 'j', "join",      "Subscribe to a service permanently",
      OPT_STR, &opt_subscribe },


    { 0, NULL, "TODO: testing", OPT_BOOL, NULL },
    { 0, "tsfile_tuners", "Number of tsfile tuners", OPT_INT, &opt_tsfile_tuner },
    { 0, "tsfile", "tsfile input (mux file)", OPT_STR_LIST, &opt_tsfile },

  };

  /* Get current directory */
  tvheadend_cwd = dirname(dirname(tvh_strdupa(argv[0])));

  /* Set locale */
  setlocale(LC_ALL, "");
  setlocale(LC_NUMERIC, "C");

  /* make sure the timezone is set */
  tzset();

  /* Process command line */
  for (i = 1; i < argc; i++) {

    /* Find option */
    cmdline_opt_t *opt
      = cmdline_opt_find(cmdline_opts, ARRAY_SIZE(cmdline_opts), argv[i]);
    if (!opt)
      show_usage(argv[0], cmdline_opts, ARRAY_SIZE(cmdline_opts),
                 "invalid option specified [%s]", argv[i]);

    /* Process */
    if (opt->type == OPT_BOOL)
      *((int*)opt->param) = 1;
    else if (++i == argc)
      show_usage(argv[0], cmdline_opts, ARRAY_SIZE(cmdline_opts),
                 "option %s requires a value", opt->lopt);
    else if (opt->type == OPT_INT)
      *((int*)opt->param) = atoi(argv[i]);
    else if (opt->type == OPT_STR_LIST) {
      str_list_t *strl = opt->param;
      if (strl->num < strl->max)
        strl->str[strl->num++] = argv[i];
    }
    else
开发者ID:joselzinga,项目名称:tvheadend-hdhomerun,代码行数:67,代码来源:main.c

示例2: pkg_repo_binary_try_fetch

static int
pkg_repo_binary_try_fetch(struct pkg_repo *repo, struct pkg *pkg,
	bool already_tried, bool mirror, const char *destdir)
{
	char dest[MAXPATHLEN];
	char url[MAXPATHLEN];
	char *dir = NULL;
	int fetched = 0;
	char cksum[SHA256_DIGEST_LENGTH * 2 +1];
	int64_t pkgsize;
	struct stat st;
	char *path = NULL;
	const char *packagesite = NULL, *repourl;

	int retcode = EPKG_OK;
	const char *name, *version, *sum;

	assert((pkg->type & PKG_REMOTE) == PKG_REMOTE);

	pkg_get(pkg, PKG_CKSUM, &sum,
			PKG_NAME, &name, PKG_VERSION, &version, PKG_PKGSIZE, &pkgsize,
			PKG_REPOPATH, &repourl);

	if (mirror) {
		const char *cachedir;

		if (destdir != NULL)
			cachedir = destdir;
		else
			cachedir = pkg_object_string(pkg_config_get("PKG_CACHEDIR"));

		snprintf(dest, sizeof(dest), "%s/%s",
						cachedir, repourl);
	}
	else
		pkg_repo_binary_get_cached_name(repo, pkg, dest, sizeof(dest));

	/* If it is already in the local cachedir, dont bother to
	 * download it */
	if (access(dest, F_OK) == 0)
		goto checksum;

	/* Create the dirs in cachedir */
	dir = strdup(dest);
	if (dir == NULL || (path = dirname(dir)) == NULL) {
		pkg_emit_errno("dirname", dest);
		retcode = EPKG_FATAL;
		goto cleanup;
	}

	if ((retcode = mkdirs(path)) != EPKG_OK)
		goto cleanup;

	/*
	 * In multi-repos the remote URL is stored in pkg[PKG_REPOURL]
	 * For a single attached database the repository URL should be
	 * defined by PACKAGESITE.
	 */
	packagesite = pkg_repo_url(repo);

	if (packagesite == NULL || packagesite[0] == '\0') {
		pkg_emit_error("PACKAGESITE is not defined");
		retcode = 1;
		goto cleanup;
	}

	if (packagesite[strlen(packagesite) - 1] == '/')
		pkg_snprintf(url, sizeof(url), "%S%R", packagesite, pkg);
	else
		pkg_snprintf(url, sizeof(url), "%S/%R", packagesite, pkg);

	if (!mirror && strncasecmp(packagesite, "file://", 7) == 0) {
		pkg_set(pkg, PKG_REPOPATH, url + 7);
		return (EPKG_OK);
	}

	retcode = pkg_fetch_file(repo, url, dest, 0);
	fetched = 1;

	if (retcode != EPKG_OK)
		goto cleanup;

checksum:
	/*	checksum calculation is expensive, if size does not
		match, skip it and assume failed checksum. */
	if (stat(dest, &st) == -1 || pkgsize != st.st_size) {
		if (already_tried) {
			pkg_emit_error("cached package %s-%s: "
				"size mismatch, cannot continue",
				name, version);
			retcode = EPKG_FATAL;
			goto cleanup;
		}

		unlink(dest);
		pkg_emit_error("cached package %s-%s: "
			"size mismatch, fetching from remote",
			name, version);
		return (pkg_repo_binary_try_fetch(repo, pkg, true, mirror, destdir));
	}
//.........这里部分代码省略.........
开发者ID:vianaweb,项目名称:pkg,代码行数:101,代码来源:fetch.c

示例3: createDirectories

void Filesystem::createDirectoriesFor(const std::string& file) {
	createDirectories(dirname(file));
}
开发者ID:Lautitia,项目名称:berkelium,代码行数:3,代码来源:Filesystem.cpp

示例4: xar_linuxattr_extract

int32_t xar_linuxattr_extract(xar_t x, xar_file_t f, const char* file, char *buffer, size_t len)
{
#if defined HAVE_SYS_XATTR_H && defined(HAVE_LSETXATTR) && !defined(__APPLE__)
	const char *fsname = "bogus";
	struct statfs sfs;
	int eaopt = 0;
	struct _linuxattr_context context;
	xar_prop_t p;
	
	memset(&context,0,sizeof(struct _linuxattr_context));
	
	/* data buffers, can't store linux attrs */
	if(len){
		return 0;
	}
	
	/* Check for EA extraction behavior */

	memset(&sfs, 0, sizeof(sfs));
	if( statfs(file, &sfs) != 0 ) {
		char *tmp, *bname;
		tmp = strdup(file);
		bname = dirname(tmp);
		statfs(bname, &sfs);
		free(tmp);
	}
	switch(sfs.f_type) {
	case EXT3_SUPER_MAGIC: fsname = "ext3"; break; /* assume ext3 */
	case JFS_SUPER_MAGIC:  fsname = "jfs" ; break;
	case REISERFS_SUPER_MAGIC:fsname = "reiser" ; break;
	case XFS_SUPER_MAGIC:  fsname = "xfs" ; break;
	};

	for(p = xar_prop_pfirst(f); p; p = xar_prop_pnext(p)) {
		const char *fs = NULL;
		const char *prop;
		const char *eaname = NULL;
		xar_prop_t tmpp;
		prop = xar_prop_getkey(p);

		if( strncmp(prop, XAR_EA_FORK, strlen(XAR_EA_FORK)) != 0 )
			continue;
		if( strlen(prop) != strlen(XAR_EA_FORK) )
			continue;

		tmpp = xar_prop_pget(p, "fstype");
		if( tmpp )
			fs = xar_prop_getvalue(tmpp);
		if( !eaopt && fs && strcmp(fs, fsname) != 0 ) {
			continue;
		}
		if( !fs )
			continue;

		tmpp = xar_prop_pget(p, "name");
		if( tmpp )
			eaname = xar_prop_getvalue(tmpp);

		context.file = file;
		context.attrname = eaname;
		xar_attrcopy_from_heap(x, f, p, xar_linuxattr_write, &context);

	}

#endif
	return 0;
}
开发者ID:ALEXGUOQ,项目名称:DocSets-for-iOS,代码行数:67,代码来源:linuxattr.c

示例5: make_policy

int
make_policy(char **type, char **data, int count, char **presult, int derive)
{
	static char result[4096];
	char one[2048];
	int i;
	int nfilename, isfilename;

	result[0] = '\0';
	nfilename = 0;
	for (i = 0; i < count; i++) {
		isfilename = 0;
		/* Special case for non existing filenames */
		if (strstr(data[i], "<non-existent filename>") != NULL) {
			snprintf(result, sizeof(result),
			    "filename%s sub \"<non-existent filename>\" then deny[enoent]", i ? "[1]" : "");
			break;
		}

		if (!strcmp(type[i], "uid") || !strcmp(type[i], "gid") ||
		    !strcmp(type[i], "argv"))
			continue;

		/* Special case for system calls with more than one filename */
		if (!strcmp(type[i], "filename")) {
			isfilename = 1;
			nfilename++;
		}
		
		if (strlen(result)) {
			if (strlcat(result, " and ", sizeof(result)) >= sizeof(result))
				return (-1);
		}

		/* Special treatment for filenames */
		if (isfilename) {
			char filename[2048];
			char *operator = "eq";

			if (derive) {
				operator = "match";

				snprintf(filename, sizeof(filename),
				    "%s/*", dirname(data[i]));
			} else
				strlcpy(filename, data[i], sizeof(filename));

			/* Make useful replacements */
			while (strrpl(filename, sizeof(filename),
				   home, "$HOME") != NULL)
				;
			while (strrpl(filename, sizeof(filename),
				   username, "$USER") != NULL)
				;

			snprintf(one, sizeof(one), "%s%s %s \"%s\"",
			    type[i], isfilename && nfilename == 2 ? "[1]" : "",
			    operator, filename);
		} else {
			snprintf(one, sizeof(one), "%s eq \"%s\"",
			    type[i], data[i]);
		}

		if (strlcat(result, one, sizeof(result)) >= sizeof(result))
			return (-1);;
	}

	if (!strlen(result))
		return (-1);

	/* Normal termination */
	if (i == count)
		strlcat(result, " then permit", sizeof(result));

	*presult = result;
	return (nfilename);
}
开发者ID:barak,项目名称:xsystrace,代码行数:77,代码来源:main.c

示例6: start_recording

stream2file_error_msg_t start_recording(const char * const filename, const char * const info, const unsigned short vpid, const unsigned short * const pids, const unsigned int numpids)
{
	int fd;
	char buf[FILENAMEBUFFERSIZE];
	struct statfs s;

	// rip rec_filename
	if(autoshift)
		sprintf(rec_filename, "%s_temp", filename);
	else
		sprintf(rec_filename, "%s", filename);

	// write stream information (should wakeup the disk from standby, too)
	sprintf(buf, "%s.xml", rec_filename);

	char * dir = strdup(buf);
	int ret = statfs(dirname(dir), &s);
	free(dir);

	if((ret != 0) || (s.f_type == 0x72b6) || (s.f_type == 0x24051905)) 
	{
		return STREAM2FILE_INVALID_DIRECTORY;
	}

	if ((fd = open(buf, O_SYNC | O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) >= 0) 
	{
		write(fd, info, strlen(info));
		fdatasync(fd);
		close(fd);
	} 
	else 
	{
		return STREAM2FILE_INVALID_DIRECTORY;
	}

	exit_flag = STREAM2FILE_STATUS_RUNNING;

	sprintf(buf, "%s.ts", rec_filename);

	dprintf(DEBUG_NORMAL, "[Stream2File] Record start: file %s vpid 0x%x apid 0x%x\n", buf, vpid, pids[0]);

	fd = open(buf, O_CREAT | O_RDWR | O_LARGEFILE | O_TRUNC , S_IRWXO | S_IRWXG | S_IRWXU);
	if(fd < 0) 
	{
		perror(buf);
		return STREAM2FILE_INVALID_DIRECTORY;
	}
	
	genpsi(fd);

	// init record
	if(!record)
	{
		if(channel)
			record = new cRecord( channel->getFeIndex() );
	}
	

	// open
	record->Open(numpids);

	// start_recording
	if(!record->Start(fd, (unsigned short ) vpid, (unsigned short *) pids, numpids)) 
	{
		record->Stop();
		delete record;
		record = NULL;
		return STREAM2FILE_INVALID_DIRECTORY;
	}
	
        if(channel)
	{
		cam0->setCaPmt(channel->getCaPmt(), 0, 1, true); // demux 0+2 , update
	}

	return STREAM2FILE_OK;
}
开发者ID:FFTEAM,项目名称:evolux-spark-sh4,代码行数:77,代码来源:stream2file.cpp

示例7: envfs_load_data

static int envfs_load_data(struct envfs_super *super, void *buf, size_t size,
		const char *dir, unsigned flags)
{
	int fd, ret = 0;
	char *str, *tmp;
	int headerlen_full;
	/* for envfs < 1.0 */
	struct envfs_inode_end inode_end_dummy;
	struct stat s;

	inode_end_dummy.mode = ENVFS_32(S_IRWXU | S_IRWXG | S_IRWXO);
	inode_end_dummy.magic = ENVFS_32(ENVFS_INODE_END_MAGIC);

	while (size) {
		struct envfs_inode *inode;
		struct envfs_inode_end *inode_end;
		uint32_t inode_size, inode_headerlen, namelen;

		inode = buf;
		buf += sizeof(struct envfs_inode);

		if (ENVFS_32(inode->magic) != ENVFS_INODE_MAGIC) {
			printf("envfs: wrong magic\n");
			ret = -EIO;
			goto out;
		}
		inode_size = ENVFS_32(inode->size);
		inode_headerlen = ENVFS_32(inode->headerlen);
		namelen = strlen(inode->data) + 1;
		if (super->major < 1)
			inode_end = &inode_end_dummy;
		else
			inode_end = buf + PAD4(namelen);

		debug("loading %s size %d namelen %d headerlen %d\n", inode->data,
			inode_size, namelen, inode_headerlen);

		str = concat_path_file(dir, inode->data);

		headerlen_full = PAD4(inode_headerlen);
		buf += headerlen_full;

		if (ENVFS_32(inode_end->magic) != ENVFS_INODE_END_MAGIC) {
			printf("envfs: wrong inode_end_magic\n");
			ret = -EIO;
			goto out;
		}

		tmp = strdup(str);
		make_directory(dirname(tmp));
		free(tmp);

		ret = stat(str, &s);
		if (!ret && (flags & ENV_FLAG_NO_OVERWRITE)) {
			printf("skip %s\n", str);
			goto skip;
		}

		if (S_ISLNK(ENVFS_32(inode_end->mode))) {
			debug("symlink: %s -> %s\n", str, (char*)buf);
			if (!strcmp(buf, basename(str))) {
				unlink(str);
			} else {
				if (!ret)
					unlink(str);

				ret = symlink(buf, str);
				if (ret < 0)
					printf("symlink: %s -> %s : %s\n",
							str, (char*)buf, strerror(-errno));
			}
			free(str);
		} else {
			fd = open(str, O_WRONLY | O_CREAT | O_TRUNC, 0644);
			free(str);
			if (fd < 0) {
				printf("Open %s\n", errno_str());
				ret = fd;
				goto out;
			}

			ret = write(fd, buf, inode_size);
			if (ret < inode_size) {
				perror("write");
				ret = -errno;
				close(fd);
				goto out;
			}
			close(fd);
		}
skip:
		buf += PAD4(inode_size);
		size -= headerlen_full + PAD4(inode_size) +
				sizeof(struct envfs_inode);
	}

	recursive_action(dir, ACTION_RECURSE | ACTION_DEPTHFIRST, NULL,
			dir_remove_action, NULL, 0);

	ret = 0;
//.........这里部分代码省略.........
开发者ID:Tractorfirmware,项目名称:barebox,代码行数:101,代码来源:environment.c

示例8: mf_fgets

/*
 * Like fgets, but go through the list of files chaining them together.
 * Set len to the length of the line.
 */
int
mf_fgets(SPACE *sp, enum e_spflag spflag)
{
	struct stat sb;
	ssize_t len;
	static char *p = NULL;
	static size_t plen = 0;
	int c;
	static int firstfile;

	if (infile == NULL) {
		/* stdin? */
		if (files->fname == NULL) {
			if (inplace != NULL)
				errx(1, "-I or -i may not be used with stdin");
			infile = stdin;
			fname = "stdin";
			outfile = stdout;
			outfname = "stdout";
		}
		firstfile = 1;
	}

	for (;;) {
		if (infile != NULL && (c = getc(infile)) != EOF) {
			(void)ungetc(c, infile);
			break;
		}
		/* If we are here then either eof or no files are open yet */
		if (infile == stdin) {
			sp->len = 0;
			return (0);
		}
		if (infile != NULL) {
			fclose(infile);
			if (*oldfname != '\0') {
				/* if there was a backup file, remove it */
				unlink(oldfname);
				/*
				 * Backup the original.  Note that hard links
				 * are not supported on all filesystems.
				 */
				if ((link(fname, oldfname) != 0) &&
				   (rename(fname, oldfname) != 0)) {
					warn("rename()");
					if (*tmpfname)
						unlink(tmpfname);
					exit(1);
				}
				*oldfname = '\0';
			}
			if (*tmpfname != '\0') {
				if (outfile != NULL && outfile != stdout)
					if (fclose(outfile) != 0) {
						warn("fclose()");
						unlink(tmpfname);
						exit(1);
					}
				outfile = NULL;
				if (rename(tmpfname, fname) != 0) {
					/* this should not happen really! */
					warn("rename()");
					unlink(tmpfname);
					exit(1);
				}
				*tmpfname = '\0';
			}
			outfname = NULL;
		}
		if (firstfile == 0)
			files = files->next;
		else
			firstfile = 0;
		if (files == NULL) {
			sp->len = 0;
			return (0);
		}
		fname = files->fname;
		if (inplace != NULL) {
			if (lstat(fname, &sb) != 0)
				err(1, "%s", fname);
			if (!(sb.st_mode & S_IFREG))
				errx(1, "%s: %s %s", fname,
				    "in-place editing only",
				    "works for regular files");
			if (*inplace != '\0') {
				strlcpy(oldfname, fname,
				    sizeof(oldfname));
				len = strlcat(oldfname, inplace,
				    sizeof(oldfname));
				if (len > (ssize_t)sizeof(oldfname))
					errx(1, "%s: name too long", fname);
			}
			len = snprintf(tmpfname, sizeof(tmpfname),
			    "%s/.!%ld!%s", dirname(fname), (long)getpid(),
			    basename(fname));
//.........这里部分代码省略.........
开发者ID:beastix,项目名称:bsdtools,代码行数:101,代码来源:main.c

示例9: main

int main(int argc, char * argv[]){

	if(argc != 2){
		printf("Usage: %s <file_path> \n", argv[0]);
		return 1;
	}

	// Prepares paths to be used during the execution
	char * basepath;
	basepath = basename(argv[1]);
	
	char * path = argv[1];

	char textFilename[MAX_BUFFER];
	strcpy(textFilename,path);

	path = dirname(path);

	char wordsFilename[MAX_BUFFER];
	strcpy(wordsFilename,path);
	strcat(wordsFilename, "/words.txt");
	char tempFilename[MAX_BUFFER];
	strcpy(tempFilename,path);
	strcat(tempFilename, "/temp");
	strcat(tempFilename, basepath);

	// Tries to open words file 
	int fdWords = open(wordsFilename, O_RDONLY);
	if(fdWords == -1){
		printf("%s\n", wordsFilename);
		perror("Words File missing...\n");
		return 2;
	}

	// Creates a new temporary file 
	int fdTemp = open(tempFilename, O_WRONLY | O_CREAT | O_TRUNC, 0777);
	if(fdTemp == -1){
		perror("Cannot creat tempFile...\n");
		return 3;
	}

	// Initializes the pipe to be used in searching process 
	int fd[2];
	pipe(fd);
	int status;
	int pid;
	char word[MAX_BUFFER];
	while(readLine(fdWords, word) != 0){
		pid = fork();
		if(pid == 0){
			close(fd[READ]);
			dup2(fd[WRITE],STDOUT_FILENO);
			// Execute searching process, result is sent to pipe
			execlp("grep", "grep", "-n", "-o", "-w" , word,textFilename,NULL);
			return 0;
		}
		else if(pid == -1){
			perror("Fork error");
			return 3; 
		}
		else{
			// Avoids zumbie processes
			waitpid(-1, &status, WNOHANG);
		}
		memset(word,0,sizeof(word));
	}

	close(fdWords);
	close(fd[WRITE]);

	char line[MAX_BUFFER];
	char * formatedLine;

	// Puts every searched words in a temporary file
	while(readLine(fd[READ], line) != 0){
		formatedLine = formatLine(line,basepath);
		write(fdTemp, formatedLine, strnlen(formatedLine, MAX_BUFFER));
		write(fdTemp, "\n", 1);
		memset(line,0,sizeof(line));
	}
	close(fdTemp);
	return 0;
}
开发者ID:Digas29,项目名称:SOPE-INDEX,代码行数:83,代码来源:sw.c

示例10: main

int
main(int argc, char **argv)
{
	int i;
	int searching = 1;
	char searchname[SPCS_S_MAXMODNAME];
	char line[SPCS_S_MAXLINE];
	char tline[SPCS_S_MAXLINE];
	char *p, *p2;

	(void) strcpy(help_path, dirname(argv[0]));
	(void) strcat(help_path, "/errgen.help");
	if ((argc == 1) || ((argc == 2) && (strcmp(argv[1], "-h") == 0))) {
		help();
		exit(0);
	}

	if (argc != 3)
		fatal("Bad number of arguments");

	p = argv[2];
	p2 = modname;

	while (*p)
		*p2++ = toupper(*p++);
	*p2 = 0;

	switch (argv[1][1]) {
	case 'c':
		mode = C_MODE;
		break;
	case 'j':
		mode = J_MODE;
		break;
	case 'e':
		mode = E_MODE;
		break;
	case 'm':
		mode = M_MODE;
		break;
	case 't':
		mode = T_MODE;
		break;
	case 'x':
		mode = X_MODE;
		break;
	default:
		fatal("Unknown option switch");
	}

	if (strcmp(modname, "DSW") == 0) {
		(void) strcpy(searchname, "II");
	} else if (strcmp(modname, "RDC") == 0) {
		(void) strcpy(searchname, "SNDR");
	} else if (strcmp(modname, "SDCTL") == 0) {
		(void) strcpy(searchname, "NSCTL");
	} else {
		(void) strcpy(searchname, modname);
	}

	i = 0;
	do {
		if (strcmp(module_names[i++], searchname) == 0) {
			searching = 0;
			mod_number = i - 1;
			break;
		}
	} while (module_names[i]);

	if (searching) {
		if (i != SPCS_M_MAX)
			(void) fprintf(stderr,
			"NULL in module_names before SPCS_M_MAX\n");
		fatal("Undefined module name");
	}

	do_preamble();

	while (!feof(stdin)) {
		(void) fgets(line, SPCS_S_MAXLINE, stdin);
		if (feof(stdin)) {
			if (count == 0)
				fatal("errgen file empty");

			do_trailer();
			exit(0);
		}
		line[strlen(line)-1] = 0;
		if ((strlen(line) != 0) && (line[0] != '#')) {
		    (void) strcpy(tline, line);
		    p = strchr(tline, ' ');
		    if (p == NULL) {
			(void) fprintf(stderr,
				    "blank separator missing at line: %d\n",
					    count);
			    fatal("");
		    }
		    *p = 0;
		    if (strlen(p) > SPCS_S_MAXKEY) {
			    (void) fprintf(stderr,
//.........这里部分代码省略.........
开发者ID:0xffea,项目名称:illumos-gate,代码行数:101,代码来源:errgen.c

示例11: ERRO

FB::variant ibrowserAPI::downloadFile(const std::string& url,const std::string& filename,const boost::optional<FB::JSObjectPtr>& pcb, F_ADD)
{
    if(url.empty() || filename.empty())
        ERRO("url or filename is empty!");
    
    THREAD(&ibrowserAPI::downloadFile,url,filename,pcb);
    
    curl_global_init(CURL_GLOBAL_ALL);
    
    double fileSize = -1;
    CURL *fileSizeCurl = curl_easy_init();
    curl_easy_setopt(fileSizeCurl, CURLOPT_URL,url.c_str());
    curl_easy_setopt(fileSizeCurl, CURLOPT_HEADER, 1);
    curl_easy_setopt(fileSizeCurl, CURLOPT_NOBODY, 1);
    curl_easy_perform(fileSizeCurl);
    curl_easy_getinfo(fileSizeCurl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &fileSize);
    curl_easy_cleanup(fileSizeCurl);
    
    log("download file size:%.0f",fileSize);
    if(0 >= fileSize)
    {
        ERRO("get file size error");
    }
    
    char tmpName[1024];
    sprintf(tmpName,"%s/%s",dirname(tmpnam(NULL)),filename.c_str());
    
    log("start download, save file:%s, use %d threads",tmpName,this->downloadThreads);
    
    double partSize=fileSize/this->downloadThreads;
    pthread_t threads[this->downloadThreads];
    std::vector<double> counter;
    for(int i=0;i<this->downloadThreads;i++)
    {
        double start=partSize*i;
        double end=0;
        if(i+1<this->downloadThreads)
            end=partSize*(i+1)-1;
        else
            end=fileSize;
        FILE *tmpFile=fopen(tmpName,"wb+");
        if(!tmpFile)
            ERRO("create tmp file error");
        fseek(tmpFile,start,SEEK_SET);
        counter.push_back(0);
        
        log("threadid:%d,range:%.0f-%.0f",i,start,end);
        DownloadConfig *cfg=new DownloadConfig(i,url,tmpFile,*pcb,fileSize,start,end,&counter);
        pthread_create(&threads[i],NULL,&ibrowserAPI::downloadThread,cfg);
    }
    
    for(int i=0; i< this->downloadThreads; i++) {
        pthread_join(threads[i], NULL);
    }
    
    curl_global_cleanup();
    
    double downloadSize=0;
    int len=counter.size();
    for(int i=0;i<len;i++)
    {
        downloadSize+=counter.at(i);
    }
    //downloadSize+=1;
    log("downloadSize:%.0f",downloadSize);
    if(downloadSize == fileSize)
    {
        SUCC(tmpName);
    }else{
        ERRO("download error");
    }
    
    
    return true;
}
开发者ID:Y1Fo,项目名称:ibrowser_plugin,代码行数:75,代码来源:ibrowserAPI.cpp

示例12: create_fullfile

/* output must be a file, which is a (compressed) tar file, of the file denoted by "file", without any of its
   directory paths etc etc */
static void create_fullfile(struct file *file)
{
	char *origin;
	char *tarname = NULL;
	char *rename_source = NULL;
	char *rename_target = NULL;
	char *rename_tmpdir = NULL;
	int ret;
	struct stat sbuf;
	char *empty, *indir, *outdir;
	char *param1, *param2;

	if (file->is_deleted) {
		return; /* file got deleted -> by definition we cannot tar it up */
	}

	empty = config_empty_dir();
	indir = config_image_base();
	outdir = config_output_dir();

	string_or_die(&tarname, "%s/%i/files/%s.tar", outdir, file->last_change, file->hash);
	if (access(tarname, R_OK) == 0) {
		/* output file already exists...done */
		free(tarname);
		return;
	}
	free(tarname);
	//printf("%s was missing\n", file->hash);

	string_or_die(&origin, "%s/%i/full/%s", indir, file->last_change, file->filename);
	if (lstat(origin, &sbuf) < 0) {
		/* no input file: means earlier phase of update creation failed */
		LOG(NULL, "Failed to stat", "%s: %s", origin, strerror(errno));
		assert(0);
	}

	if (file->is_dir) { /* directories are easy */
		char *tmp1, *tmp2, *dir, *base;

		tmp1 = strdup(origin);
		assert(tmp1);
		base = basename(tmp1);

		tmp2 = strdup(origin);
		assert(tmp2);
		dir = dirname(tmp2);

		string_or_die(&rename_tmpdir, "%s/XXXXXX", outdir);
		if (!mkdtemp(rename_tmpdir)) {
			LOG(NULL, "Failed to create temporary directory for %s move", origin);
			assert(0);
		}

		string_or_die(&param1, "--exclude=%s/?*", base);
		string_or_die(&param2, "./%s", base);
		char *const tarcfcmd[] = { TAR_COMMAND, "-C", dir, TAR_PERM_ATTR_ARGS_STRLIST, "-cf", "-", param1, param2, NULL };
		char *const tarxfcmd[] = { TAR_COMMAND, "-C", rename_tmpdir, TAR_PERM_ATTR_ARGS_STRLIST, "-xf", "-", NULL };

		int tarcmdresult = system_argv_pipe(tarcfcmd, tarxfcmd);
		if (tarcmdresult != 0) {
			LOG(NULL, "Tar command for copying directory full file failed with code %d", tarcmdresult);
			assert(0);
		}
		free(param1);
		free(param2);

		string_or_die(&rename_source, "%s/%s", rename_tmpdir, base);
		string_or_die(&rename_target, "%s/%s", rename_tmpdir, file->hash);
		if (rename(rename_source, rename_target)) {
			LOG(NULL, "rename failed for %s to %s", rename_source, rename_target);
			assert(0);
		}
		free(rename_source);

		/* for a directory file, tar up simply with gzip */
		string_or_die(&param1, "%s/%i/files/%s.tar", outdir, file->last_change, file->hash);
		char *const tarcmd[] = { TAR_COMMAND, "-C", rename_tmpdir, TAR_PERM_ATTR_ARGS_STRLIST, "-zcf", param1, file->hash, NULL };

		if (system_argv(tarcmd) != 0) {
			assert(0);
		}
		free(param1);

		if (rmdir(rename_target)) {
			LOG(NULL, "rmdir failed for %s", rename_target);
		}
		free(rename_target);
		if (rmdir(rename_tmpdir)) {
			LOG(NULL, "rmdir failed for %s", rename_tmpdir);
		}
		free(rename_tmpdir);

		free(tmp1);
		free(tmp2);
	} else { /* files are more complex */
		char *gzfile = NULL, *bzfile = NULL, *xzfile = NULL;
		char *tempfile;
		uint64_t gz_size = LONG_MAX, bz_size = LONG_MAX, xz_size = LONG_MAX;
//.........这里部分代码省略.........
开发者ID:clearlinux,项目名称:swupd-server,代码行数:101,代码来源:fullfiles.c

示例13: main

// This is Scramble.
int main(int argc, string argv[])
{
    // ensure proper usage
    if (argc > 2)
    {
        printf("Usage: %s [#]\n", basename(argv[0]));
        return 1;
    }

    // seed pseudorandom number generator
    if (argc == 2)
    {
        int seed = atoi(argv[1]);
        if (seed <= 0)
        {
            printf("Invalid grid.\n");
            return 1;
        }
        srand(seed);
    }
    else
        srand(time(NULL));

    // determine path to dictionary
    string directory = dirname(argv[0]);
    char path[strlen(directory) + 1 + strlen(DICTIONARY) + 1];
    sprintf(path, "%s/%s", directory, DICTIONARY);

    // load dictionary
    if (!load(path))
    {
        printf("Could not open dictionary.\n");
        return 1;
    }

    // initialize the grid
    initialize();

    // initialize user's score
    int score = 0;

    // calculate time of game's end
    int end = time(NULL) + DURATION;

    // open log
    log = fopen("log.txt", "a");
    if (log == NULL)
    {
        printf("Could not open log.\n");
        return 1;
    }

    // accept words until timer expires
    while (true)
    {
        // clear the screen
        clear();

        // draw the current state of the grid
        draw();

        // log board
        for (int row = 0; row < DIMENSION; row++)
        {
            for (int col = 0; col < DIMENSION; col++)
                fprintf(log, "%c", grid[row][col]);
            fprintf(log, "\n");
        }

        // get current time
        int now = time(NULL);

        // report score
        printf("Score: %d\n", score);
        fprintf(log, "%d\n", score);

        // check for game's end
        if (now >= end)
        {
            printf("\033[31m"); // red
            printf("Time:  %d\n\n", 0);
            printf("\033[39m"); // default
            break;
        }

        // report time remaining
        printf("Time:  %d\n\n", end - now);

        // prompt for word
        printf("> ");
        string word = GetString();
        if (word != NULL)
        {
            //define the string length as an integer
            int word_length = strlen(word);

            //set each individual character in the string to be uppercase
            for(int i=0; i < word_length; i++)
                word[i] = toupper(word[i]);
//.........这里部分代码省略.........
开发者ID:alexbukhta,项目名称:CS50,代码行数:101,代码来源:scramble.c

示例14: tiny_mkdir

int tiny_mkdir(const char *path, mode_t mode)
{
	tiny_inode		i_tmp, parent_inode;
	tiny_dentry		*d_tmp, *child_dentry;

	char *token;
	char *path_copy;
	char *dir_name;
	char *base_name;
	int i, j;
	int ret = 0;

	if ( strlen(path) > NAME_LEN_MAX - 1/*\0*/ ) {
		return -ENAMETOOLONG;
	}

	/* Get inode of the parent directory */
	path_copy = (char*)malloc(strlen(path) + 1);
	strcpy(path_copy, path);
	dir_name = dirname(path_copy);
	token = strtok(dir_name, "/");
	ReadInode(&i_tmp, tiny_superblk.s_rdirino);
	memcpy(&parent_inode, &i_tmp, sizeof(tiny_inode));

	while (token) {
		memcpy(&parent_inode, &i_tmp, sizeof(tiny_inode));
		d_tmp = __find_dentry(&i_tmp, token);
		if (!d_tmp || d_tmp->type == FILE_TYPE_FILE) {
			ret = -ENOTDIR;
			goto err;
		}

		ReadInode(&i_tmp, d_tmp->inodeNum);
		token = strtok(NULL, "/");
	}

	/* Get dentry of the target */
	free(path_copy);
	path_copy = (char*)malloc(strlen(path) + 1);
	strcpy(path_copy, path);
	base_name = basename(path_copy);
	child_dentry = __find_dentry(&i_tmp, base_name);

	/* There is no such file */
	if (child_dentry == NULL) {
		// make a directory!!
		if ( MakeDirentry(&parent_inode, base_name) == WRONG_VALUE ) {
			return -EDQUOT;
		}
		goto err;
	} else {
		// already file exists
		ret = -EEXIST;
		goto err;
	}

err:
	free(child_dentry);
	free(path_copy);

	return ret;
}
开发者ID:withmelody,项目名称:SW_Project,代码行数:62,代码来源:op_mkdir.c

示例15: dirname

/*
==================
Sys_Dirname
==================
*/
const char *Sys_Dirname( char *path )
{
	return dirname( path );
}
开发者ID:Call-of-Duty-Scripts,项目名称:CoD4X17a_testing,代码行数:9,代码来源:sys_unix.c


注:本文中的dirname函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。