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


C++ xopen函数代码示例

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


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

示例1: setlogcons_main

int setlogcons_main(int argc UNUSED_PARAM, char **argv)
{
	struct {
		char fn;
		char subarg;
	} arg = { 11, /* redirect kernel messages */
			  0   /* to specified console (current as default) */
			};

	if (argv[1])
		arg.subarg = xatou_range(argv[1], 0, 63);

	xioctl(xopen(VC_1, O_RDONLY), TIOCLINUX, &arg);

	return EXIT_SUCCESS;
}
开发者ID:593141477,项目名称:Learning-Linux,代码行数:16,代码来源:setlogcons.c

示例2: sendevent_main

void sendevent_main(void)
{
  int fd = xopen(*toys.optargs, O_RDWR);
  int version;
  struct input_event ev;

  if (ioctl(fd, EVIOCGVERSION, &version))
    perror_exit("EVIOCGVERSION failed for %s", *toys.optargs);
  
  memset(&ev, 0, sizeof(ev));
  // TODO: error checking and support for named constants.
  ev.type = atoi(toys.optargs[1]);
  ev.code = atoi(toys.optargs[2]);
  ev.value = atoi(toys.optargs[3]);
  xwrite(fd, &ev, sizeof(ev));
}
开发者ID:emaste,项目名称:toybox,代码行数:16,代码来源:sendevent.c

示例3: main

int			main(int ac, char **av)
{
	int		fd;
	t_raw	raw;
	t_data	data;
	t_env	env;

	read_args(&env, ac, av);
	get_env(&env, av[1]);
	fd = xopen(av[1], O_RDONLY);
	raw = read_file(fd);
	close(fd);
	data = read_raw(raw);
	display_data(data, env);
	mlx_loop(env.mlx);
	return (1);
}
开发者ID:lgarczyn,项目名称:fdf,代码行数:17,代码来源:fdf.c

示例4: open_file_and_read_lines

static void open_file_and_read_lines(void)
{
    if (filename) {
        int fd = xopen(filename, O_RDONLY);
        dup2(fd, 0);
        if (fd) close(fd);
    } else {
        /* "less" with no arguments in argv[] */
        /* For status line only */
        filename = xstrdup(bb_msg_standard_input);
    }
    readpos = 0;
    readeof = 0;
    linepos = 0;
    terminated = 1;
    read_lines();
}
开发者ID:OPSF,项目名称:uClinux,代码行数:17,代码来源:less.c

示例5: syslinux_execute

void syslinux_execute(void)
{
	char *device, *diskdevice;
	char *bootimages;
	int fd;

	if (strcmp(hashmapGetPrintf(ictx.opts, "none", BASE_BOOTLOADER),
				"syslinux"))
		return;

	pr_info("Writing MBR");
        diskdevice = xasprintf("/dev/block/%s",
			hashmapGetPrintf(ictx.opts, NULL, BASE_INSTALL_DISK));
	dd(SYSLINUX_MBR, diskdevice);
        free(diskdevice);

	/* SYSLINUX complains if this isn't done */
	chmod("/tmp", 01777);

	bootimages = hashmapGetPrintf(ictx.opts, NULL, BASE_BOOT_LIST);
	device = hashmapGetPrintf(ictx.opts, NULL, "partition.bootloader:device");
	pr_info("Installing ldlinux.sys onto %s", device);
	do_install_syslinux(device);

	/* In case we die() before we are finished */
	signal(SIGABRT, sighandler);
	mount_partition_device(device, "vfat", BOOTLOADER_PATH);

	pr_info("Copying syslinux support files");
	copy_file(IMAGES_PATH "vesamenu.c32", BOOTLOADER_PATH "vesamenu.c32");
	copy_file(IMAGES_PATH "android.c32", BOOTLOADER_PATH "android.c32");

	pr_info("Constructing syslinux.cfg");
	/* Put the initial template stuff in */
	copy_file(SYSLINUX_CFG_TEM_FN, SYSLINUX_CFG_FN);
	fd = xopen(SYSLINUX_CFG_FN, O_WRONLY | O_APPEND);
	put_string(fd, "menu androidcommand %s\n",
		hashmapGetPrintf(ictx.opts, NULL, "partition.misc:index"));
	string_list_iterate(bootimages, bootimage_cb, &fd);

	xclose(fd);
	umount(BOOTLOADER_PATH);
	rmdir(BOOTLOADER_PATH);
	signal(SIGABRT, SIG_DFL);
	pr_info("SYSLINUX installation complete");
}
开发者ID:quanganh2627,项目名称:platform_bootable_iago,代码行数:46,代码来源:iago-syslinux.c

示例6: build_code

static void build_code(char *str)
{
  char *args[] = {"as", "--32", SFILE_WRITE, "-o", BFILE_WRITE, NULL};
  Elf32_Ehdr  *aspElf_Header;
  Elf32_Shdr  *aspElf_Shdr;
  Elf32_Off   offset;
  struct stat sts;
  uint32_t    size;
  int         status;
  void        *map;
  pid_t       pid;
  int         fd;

  del_files();
  write_source_file(str);
  pid = fork();
  if (pid == 0)
    {
      execvp(args[0], args);
      exit(EXIT_SUCCESS);
    }
  waitpid(pid, &status, 0);

  if (stat(BFILE_WRITE, &sts) == -1)
    exit(EXIT_FAILURE);

  fd = xopen(BFILE_WRITE, O_RDONLY, 0644);
  map = xmmap(0, sts.st_size, PROT_READ, MAP_SHARED, fd, 0);

  aspElf_Header = map;
  aspElf_Shdr = (Elf32_Shdr *)((char *)map + aspElf_Header->e_shoff);

  offset = return_info_text(0, map, aspElf_Header, aspElf_Shdr);
  size = return_info_text(1, map, aspElf_Header, aspElf_Shdr);

  asm_mode.size = size;
  asm_mode.opcode = xmalloc((size * sizeof(char)) + 1);
  asm_mode.argument = str;
  memcpy((char *)asm_mode.opcode, (char *)map + offset, asm_mode.size);
  opcode_mode.flag = 1;
  opcode_mode.size = asm_mode.size;
  opcode_mode.opcode = asm_mode.opcode;

  xclose(fd);
  del_files();
}
开发者ID:7h3rAm,项目名称:ROPgadget,代码行数:46,代码来源:check_asm_mode.c

示例7: watchdog_main

int watchdog_main(int argc, char **argv)
{
	unsigned opts;
	unsigned timer_duration = 30000; /* Userspace timer duration, in milliseconds */
	char *t_arg;

	opt_complementary = "=1"; /* must have 1 argument */
	opts = getopt32(argv, "Ft:", &t_arg);

	if (opts & OPT_TIMER) {
		static const struct suffix_mult suffixes[] = {
			{ "ms", 1 },
			{ "", 1000 },
			{ }
		};
		timer_duration = xatou_sfx(t_arg, suffixes);
	}

	if (!(opts & OPT_FOREGROUND)) {
		bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
	}

	bb_signals(BB_FATAL_SIGS, watchdog_shutdown);

	/* Use known fd # - avoid needing global 'int fd' */
	xmove_fd(xopen(argv[argc - 1], O_WRONLY), 3);

// TODO?
//	if (!(opts & OPT_TIMER)) {
//		if (ioctl(fd, WDIOC_GETTIMEOUT, &timer_duration) == 0)
//			timer_duration *= 500;
//		else
//			timer_duration = 30000;
//	}

	while (1) {
		/*
		 * Make sure we clear the counter before sleeping, as the counter value
		 * is undefined at this point -- PFM
		 */
		write(3, "", 1); /* write zero byte */
		usleep(timer_duration * 1000L);
	}
	return EXIT_SUCCESS; /* - not reached, but gcc 4.2.1 is too dumb! */
}
开发者ID:aYosukeAkatsuka,项目名称:edimax-br-6528n,代码行数:45,代码来源:watchdog.c

示例8: nohup_main

int nohup_main(int argc, char **argv)
{
	int nullfd;
	const char *nohupout;
	char *home = NULL;

	xfunc_error_retval = 127;

	if (argc < 2) bb_show_usage();

	nullfd = xopen(bb_dev_null, O_WRONLY|O_APPEND);
	/* If stdin is a tty, detach from it. */
	if (isatty(STDIN_FILENO))
		dup2(nullfd, STDIN_FILENO);

	nohupout = "nohup.out";
	/* Redirect stdout to nohup.out, either in "." or in "$HOME". */
	if (isatty(STDOUT_FILENO)) {
		close(STDOUT_FILENO);
		if (open(nohupout, O_CREAT|O_WRONLY|O_APPEND, S_IRUSR|S_IWUSR) < 0) {
			home = getenv("HOME");
			if (home) {
				nohupout = concat_path_file(home, nohupout);
				xopen3(nohupout, O_CREAT|O_WRONLY|O_APPEND, S_IRUSR|S_IWUSR);
			}
		}
	} else dup2(nullfd, STDOUT_FILENO);

	/* If we have a tty on stderr, announce filename and redirect to stdout.
	 * Else redirect to /dev/null.
	 */
	if (isatty(STDERR_FILENO)) {
		bb_error_msg("appending to %s", nohupout);
		dup2(STDOUT_FILENO, STDERR_FILENO);
	} else dup2(nullfd, STDERR_FILENO);

	if (nullfd > 2)
		close(nullfd);
	signal(SIGHUP, SIG_IGN);

	BB_EXECVP(argv[1], argv+1);
	if (ENABLE_FEATURE_CLEAN_UP && home)
		free((char*)nohupout);
	bb_simple_perror_msg_and_die(argv[1]);
}
开发者ID:acassis,项目名称:emlinux-ssd1935,代码行数:45,代码来源:nohup.c

示例9: cmd_scalebranch

void cmd_scalebranch()
{
  int i;
  int nodes_count;
  FILE * out;

  /* attempt to open output file */
  out = opt_outfile ?
          xopen(opt_outfile,"w") : stdout;

  /* parse tree */
  if (!opt_quiet)
    fprintf(stdout, "Parsing tree file...\n");

  rtree_t * rtree = rtree_parse_newick(opt_treefile);

  if (!rtree)
    fatal("Tree must be rooted...");

  nodes_count = 2*rtree->leaves-1;
  rtree_t ** nodes = (rtree_t **)xmalloc(nodes_count*sizeof(rtree_t *));

  /* get all nodes */
  rtree_query_tipnodes(rtree, nodes);
  rtree_query_innernodes(rtree, nodes+rtree->leaves);

  for (i=0; i < nodes_count; ++i)
    nodes[i]->length *= opt_scalebranch_factor;

  
  char * newick = rtree_export_newick(rtree);

  fprintf(out, "%s\n", newick);

  if (opt_outfile)
    fclose(out);

  free(newick);
  
  /* deallocate tree structure */
  rtree_destroy(rtree);

  if (!opt_quiet)
    fprintf(stdout, "\nDone...\n");
}
开发者ID:xflouris,项目名称:newick-tools,代码行数:45,代码来源:newick-tools.c

示例10: main

int		main(int ac, char **av)
{
  t_open	*opn;
  t_list	*list;

  if (ac == 1)
    {
      my_putstr("asm: fatal error: no input file\n");
      my_putstr("Compilation terminated\n");
      return (0);
    }
  else
    {
      struct_init(&opn, &list);
      xopen(av[1], opn, list);
    }
  return (0);
}
开发者ID:Ezirel,项目名称:Corewar,代码行数:18,代码来源:main.c

示例11: i2c_dev_open

/*
 * Opens the device file associated with given i2c bus.
 *
 * Upstream i2c-tools also support opening devices by i2c bus name
 * but we drop it here for size reduction.
 */
static int i2c_dev_open(int i2cbus)
{
	char filename[sizeof("/dev/i2c-%d") + sizeof(int)*3];
	int fd;

	sprintf(filename, "/dev/i2c-%d", i2cbus);
	fd = open(filename, O_RDWR);
	if (fd < 0) {
		if (errno == ENOENT) {
			filename[8] = '/'; /* change to "/dev/i2c/%d" */
			fd = xopen(filename, O_RDWR);
		} else {
			bb_perror_msg_and_die("can't open '%s'", filename);
		}
	}

	return fd;
}
开发者ID:AlexShiLucky,项目名称:busybox,代码行数:24,代码来源:i2c_tools.c

示例12: testDistrib

void testDistrib(){
	float dd[1000]; memset(dd,0,sizeof(dd));
	for(int i=0; i<profileLength; i++){
		float xx=fProfile->get(i);
		if(xx==NA) dd[0]++;
		else{
			float x=log(1+xx);
			int k=(int)(x/10*1000)+1;
			dd[k]++;
		}
	}

	FILE *f=xopen("dstr","wt");
	for(int i=0; i<1000; i++){
		fprintf(f,"%5.2f\t%6f\n",i*10./1000.,dd[i]);
	}
	fclose(f);
}
开发者ID:favorov,项目名称:stereogene,代码行数:18,代码来源:trackPrepare.cpp

示例13: sizeof

bwa_seqio_t *bwa_bam_open(const char *fn, int which, char **saif,
                          gap_opt_t *o0, bam_header_t **hh)
{
    int c, b=0;
    bwa_seqio_t *bs;
    bam_header_t *h;
    bs = (bwa_seqio_t*)calloc(1, sizeof(bwa_seqio_t));
    bs->is_bam = 1;
    bs->which = which;
    bs->fp = (fn[0]!='-' || fn[1]) ? bam_open(fn, "r") : bam_dopen(0, "r") ;
    h = bam_header_read(bs->fp);
    if(hh) *hh=h;
    else bam_header_destroy(h);

    if( saif ) for(c=0; c!=3; ++c)
        {
            gap_opt_t opt;
            if( saif[c] ) {
                bs->sai[c] = xopen(saif[c], "r");
                if( 1 > fread(&opt, sizeof(gap_opt_t), 1, bs->sai[c]) )
                {
                    fclose(bs->sai[c]);
                    bs->sai[c] = 0;
                }
                opt.n_threads=o0->n_threads;
                if(o0) {
                    if(b) {
                        opt.mode=o0->mode;
                        if( memcmp(o0, &opt, sizeof(gap_opt_t)) ) {
                            fprintf( stderr, "[bwa_bam_open] options from sai file \"%s\" conflict with others.\n", saif[c] ) ;
                            exit(1);
                        }
                        fprintf( stderr, "[bwa_bam_open] options from sai file \"%s\" match.\n", saif[c] ) ;
                    }
                    else {
                        fprintf( stderr, "[bwa_bam_open] recovered options from sai file \"%s\".\n", saif[c] ) ;
                        memcpy(o0, &opt, sizeof(gap_opt_t));
                        b=1;
                    }
                }
            }
        }
    return bs;
}
开发者ID:mpieva,项目名称:network-aware-bwa,代码行数:44,代码来源:bwaseqio.c

示例14: write_ar_archive

static int write_ar_archive(archive_handle_t *handle)
{
	struct stat st;
	archive_handle_t *out_handle;

	if (fstat(handle->src_fd, &st) == -1)
		bb_simple_perror_msg_and_die(handle->ar__name);

	/* if archive exists, create a new handle for output.
	 * we create it in place of the old one.
	 */
	if (st.st_size != 0) {
		out_handle = init_handle();
		xunlink(handle->ar__name);
		out_handle->src_fd = xopen(handle->ar__name, O_WRONLY | O_CREAT | O_TRUNC);
		out_handle->accept = handle->accept;
	} else {
		out_handle = handle;
	}

	handle->ar__out = out_handle;

	xwrite(out_handle->src_fd, AR_MAGIC "\n", AR_MAGIC_LEN + 1);
	out_handle->offset += AR_MAGIC_LEN + 1;

	/* skip to the end of the archive if we have to append stuff */
	if (st.st_size != 0) {
		handle->filter = filter_replaceable;
		handle->action_data = copy_data;
		unpack_ar_archive(handle);
	}

	while (write_ar_header(out_handle) == 0)
		continue;

	/* optional, since we exit right after we return */
	if (ENABLE_FEATURE_CLEAN_UP) {
		close(handle->src_fd);
		if (out_handle->src_fd != handle->src_fd)
			close(out_handle->src_fd);
	}

	return EXIT_SUCCESS;
}
开发者ID:Ayyayay,项目名称:busybox,代码行数:44,代码来源:ar.c

示例15: daemonize

static int daemonize(void)
{
	int fd;
	int pid = fork();
	if (pid < 0) /* error */
		return -errno;
	if (pid > 0) /* parent */
		return 0;
	/* child */
	fd = xopen(bb_dev_null, O_RDWR);
	dup2(fd, 0);
	dup2(fd, 1);
	dup2(fd, 2);
	while (fd > 2) close(fd--);
	setsid();
	openlog(applet_name, LOG_PID, LOG_DAEMON);
	logmode = LOGMODE_SYSLOG;
	return 1;
}
开发者ID:AlickHill,项目名称:Lantern,代码行数:19,代码来源:mount.c


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