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


C++ writex函数代码示例

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


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

示例1: restart_root_service

void restart_root_service(int fd, void *cookie)
{
    char buf[100];
    char value[PROPERTY_VALUE_MAX];

    if (getuid() == 0) {
        snprintf(buf, sizeof(buf), "adbd is already running as root\n");
        writex(fd, buf, strlen(buf));
        adb_close(fd);
    } else {
        property_get("ro.debuggable", value, "");
        if (strcmp(value, "1") != 0) {
            snprintf(buf, sizeof(buf),
                     "adbd cannot run as root in production builds\n");
            writex(fd, buf, strlen(buf));
            adb_close(fd);
            return;
        }

        property_set("service.adb.root", "1");
        snprintf(buf, sizeof(buf), "restarting adbd as root\n");
        writex(fd, buf, strlen(buf));
        adb_close(fd);
    }
}
开发者ID:lovejavaee,项目名称:lucy,代码行数:25,代码来源:services.c

示例2: framebuffer_service

void framebuffer_service(int fd, void *cookie)
{
    struct fb_var_screeninfo vinfo;
    int fb;
    void *ptr = MAP_FAILED;
    char x;

    unsigned fbinfo[4];

    fb = open("/dev/graphics/fb0", O_RDONLY);
    if(fb < 0) goto done;

    if(ioctl(fb, FBIOGET_VSCREENINFO, &vinfo) < 0) goto done;
    fcntl(fb, F_SETFD, FD_CLOEXEC);

    fbinfo[0] = 16;
    fbinfo[1] = vinfo.xres * vinfo.yres * 2;
    fbinfo[2] = vinfo.xres;
    fbinfo[3] = vinfo.yres;

    ptr = mmap(0, fbinfo[1], PROT_READ, MAP_SHARED, fb, 0);
    if(ptr == MAP_FAILED) goto done;

    if(writex(fd, fbinfo, sizeof(unsigned) * 4)) goto done;

    for(;;) {
        if(readx(fd, &x, 1)) goto done;
        if(writex(fd, ptr, fbinfo[1])) goto done;
    }

done:
    if(ptr != MAP_FAILED) munmap(ptr, fbinfo[1]);
    if(fb >= 0) close(fb);
    close(fd);
}
开发者ID:Katarzynasrom,项目名称:patch-hosting-for-android-x86-support,代码行数:35,代码来源:framebuffer_service.c

示例3: reboot_service

void reboot_service(int fd, void *arg)
{
    char buf[100];
    char property_val[PROPERTY_VALUE_MAX];
    int ret;

    sync();

    ret = snprintf(property_val, sizeof(property_val), "reboot,%s", (char *) arg);
    if (ret >= (int) sizeof(property_val)) {
        snprintf(buf, sizeof(buf), "reboot string too long. length=%d\n", ret);
        writex(fd, buf, strlen(buf));
        goto cleanup;
    }

    ret = property_set(ANDROID_RB_PROPERTY, property_val);
    if (ret < 0) {
        snprintf(buf, sizeof(buf), "reboot failed: %d\n", ret);
        writex(fd, buf, strlen(buf));
        goto cleanup;
    }
    // Don't return early. Give the reboot command time to take effect
    // to avoid messing up scripts which do "adb reboot && adb wait-for-device"
    while(1) { pause(); }
cleanup:
    free(arg);
    adb_close(fd);
}
开发者ID:GameTheory-,项目名称:mkbootimg,代码行数:28,代码来源:services.c

示例4: sync_readtime

int sync_readtime(int fd, const char *path, unsigned int *timestamp,
                  unsigned int *mode)
{
    syncmsg msg;
    int len = strlen(path);

    msg.req.id = ID_STAT;
    msg.req.namelen = htoll(len);

    if(writex(fd, &msg.req, sizeof(msg.req)) ||
       writex(fd, path, len)) {
        return -1;
    }

    if(readx(fd, &msg.stat, sizeof(msg.stat))) {
        return -1;
    }

    if(msg.stat.id != ID_STAT) {
        return -1;
    }

    *timestamp = ltohl(msg.stat.time);
    *mode = ltohl(msg.stat.mode);
    return 0;
}
开发者ID:phybio,项目名称:adb,代码行数:26,代码来源:file_sync_client.c

示例5: bootimage_write

int bootimage_write(bootimage *img, int fd) {
	unsigned off = 4096;
	unsigned n, s;
	if (writex(fd, img->entry, 4096)) {
		return -1;
	}
	for (n = 1; n < 64; n++) {
		if (img->offset[n] == 0) continue;
		if (img->offset[n] < off) return -1;
		s = img->offset[n] - off;
		if (s > 4095) return -1;
		if (writex(fd, filler, s)) {
			return -1;
		}
		off += s;
		if (writex(fd, img->data[n], img->length[n])) {
			return -1;
		}
		off += img->length[n];
	}
	if (off & 4095) {
		if (writex(fd, filler, 4096 - (off & 4095))) return -1;
	}
	return 0;
}
开发者ID:M1cha,项目名称:lk,代码行数:25,代码来源:bootimage.c

示例6: execute

/* Tokenize the command buffer, locate a matching command,
 * ensure that the required number of arguments are provided,
 * call the function(), return the result.
 */
static int execute(int s, char cmd[BUFFER_MAX])
{
    char reply[REPLY_MAX];
    unsigned n = 0;
    unsigned short count;
    int ret = -1;

    /* default reply is "" */
    reply[0] = 0;

    //Check which command was received
    if (!strcmp("cpu", cmd)) {
        FILE *f = fopen(CPU_PATH, "rb");

        count = fread(reply, 1, REPLY_MAX, f);
        fclose(f);

        reply[count] = 0;
        
        goto done;
    }
    if (!strcmp("memory", cmd)) {
        FILE *f = fopen(MEM_PATH, "rb");

        count = fread(reply, 1, REPLY_MAX, f);
        fclose(f);

        reply[count] = 0;

        goto done;
    }
    if (!strcmp("cmdline", cmd)) {
        FILE *f = fopen(CMD_PATH, "rb");

        count = fread(reply, 1, REPLY_MAX, f);
        fclose(f);

        reply[count] = 0;

        goto done;
    }

    ALOGE("unsupported command '%s'\n", cmd);

done:
    ALOGI("Read %d bytes\n", count);
    if (reply[0]) {
        n = snprintf(cmd, BUFFER_MAX, "%s", reply);
    } else {
        n = snprintf(cmd, BUFFER_MAX, "%d", ret);
    }
    if (n > BUFFER_MAX) n = BUFFER_MAX;
    count = n;

    ALOGI("reply: '%s'\n", cmd);
    if (writex(s, &count, sizeof(count))) return -1;
    if (writex(s, cmd, count)) return -1;
    return 0;
}
开发者ID:devunwired,项目名称:plustwo,代码行数:63,代码来源:sysinfo.c

示例7: framebuffer_service

void framebuffer_service(int fd, void *cookie)
{
    char x[512];

    struct fbinfo fbinfo;
    int w, h, f;
    int s[2];
    int fb;
    unsigned int i;
    int rv;

    if(adb_socketpair(s)) {
        printf("cannot create service socket pair\n");
        goto done;
    }

    pid_t pid = fork();
    if (pid < 0) {
        printf("- fork failed: %s -\n", strerror(errno));
        goto done;
    }

    if (pid == 0) {
        dup2(s[1], STDOUT_FILENO);
        const char* cmd_path = "/system/bin/screencap";
        const char* cmd = "screencap";
        execl(cmd_path, cmd, NULL);
        exit(1);
    }

    fb = s[0];

    /* read w, h, f */
    if (readx(fb, &w, 4)) goto done;
    if (readx(fb, &h, 4)) goto done;
    if (readx(fb, &f, 4)) goto done;

    fbinfo.version = DDMS_RAWIMAGE_VERSION;
    fbinfo.size = w * h * 4;
    fbinfo.width = w;
    fbinfo.height = h;
    rv = fill_format(&fbinfo, f);
    if (rv != 0) goto done;

    if(writex(fd, &fbinfo, sizeof(fbinfo))) goto done;

    for(i = 0; i < fbinfo.size; i += sizeof(x)) {
        if(readx(fb, &x, sizeof(x))) goto done;
        if(writex(fd, &x, sizeof(x))) goto done;
    }

    if(readx(fb, &x, fbinfo.size % sizeof(x))) goto done;
    if(writex(fd, &x, fbinfo.size % sizeof(x))) goto done;

done:
    adb_close(s[0]);
    adb_close(s[1]);
    adb_close(fd);
}
开发者ID:OMFGB,项目名称:system_core,代码行数:59,代码来源:framebuffer_service.c

示例8: send_msg_with_okay

static void send_msg_with_okay(int fd, const char* msg, size_t msglen) {
    char header[9];
    if (msglen > 0xffff)
        msglen = 0xffff;
    snprintf(header, sizeof(header), "OKAY%04x", (unsigned)msglen);
    writex(fd, header, 8);
    writex(fd, msg, msglen);
}
开发者ID:SAOSP,项目名称:platform_system_core,代码行数:8,代码来源:adb.c

示例9: execute

/* Tokenize the command buffer, locate a matching command,
 * ensure that the required number of arguments are provided,
 * call the function(), return the result.
 */
static int execute(int s, char cmd[BUFFER_MAX])
{
    char reply[REPLY_MAX];
    char *arg[TOKEN_MAX+1];
    unsigned i;
    unsigned n = 0;
    unsigned short count;
    int ret = -1;

//    ALOGI("execute('%s')\n", cmd);

        /* default reply is "" */
    reply[0] = 0;

        /* n is number of args (not counting arg[0]) */
    arg[0] = cmd;
    while (*cmd) {
        if (isspace(*cmd)) {
            *cmd++ = 0;
            n++;
            arg[n] = cmd;
            if (n == TOKEN_MAX) {
                ALOGE("too many arguments\n");
                goto done;
            }
        }
        cmd++;
    }

    for (i = 0; i < sizeof(cmds) / sizeof(cmds[0]); i++) {
        if (!strcmp(cmds[i].name,arg[0])) {
            if (n != cmds[i].numargs) {
                ALOGE("%s requires %d arguments (%d given)\n",
                     cmds[i].name, cmds[i].numargs, n);
            } else {
                ret = cmds[i].func(arg + 1, reply);
            }
            goto done;
        }
    }
    ALOGE("unsupported command '%s'\n", arg[0]);

done:
    if (reply[0]) {
        n = snprintf(cmd, BUFFER_MAX, "%d %s", ret, reply);
    } else {
        n = snprintf(cmd, BUFFER_MAX, "%d", ret);
    }
    if (n > BUFFER_MAX) n = BUFFER_MAX;
    count = n;

//    ALOGI("reply: '%s'\n", cmd);
    if (writex(s, &count, sizeof(count))) return -1;
    if (writex(s, cmd, count)) return -1;
    return 0;
}
开发者ID:Android4SAM,项目名称:platform_frameworks_base,代码行数:60,代码来源:installd.c

示例10: sendfailmsg

int sendfailmsg(int fd, const char *reason)
{
    char buf[9];
    int len;
    len = strlen(reason);
    if(len > 0xffff) len = 0xffff;
    _snprintf(buf, sizeof buf, "FAIL%04x", len);
    if(writex(fd, buf, 8)) return -1;
    return writex(fd, reason, len);
}
开发者ID:cyf2004,项目名称:AndroidAdb,代码行数:10,代码来源:sockets.c

示例11: framebuffer_service

void framebuffer_service(int fd, void *cookie)
{
    struct fb_var_screeninfo vinfo;
    int fb, offset;
    char x[256];

    struct fbinfo fbinfo;
    unsigned i, bytespp;

    fb = open("/dev/graphics/fb0", O_RDONLY);
    if(fb < 0) goto done;

    if(ioctl(fb, FBIOGET_VSCREENINFO, &vinfo) < 0) goto done;
    fcntl(fb, F_SETFD, FD_CLOEXEC);

    bytespp = vinfo.bits_per_pixel / 8;

    fbinfo.version = DDMS_RAWIMAGE_VERSION;
    fbinfo.bpp = vinfo.bits_per_pixel;
    fbinfo.size = vinfo.xres * vinfo.yres * bytespp;
    fbinfo.width = vinfo.xres;
    fbinfo.height = vinfo.yres;
    fbinfo.red_offset = vinfo.red.offset;
    fbinfo.red_length = vinfo.red.length;
    fbinfo.green_offset = vinfo.green.offset;
    fbinfo.green_length = vinfo.green.length;
    fbinfo.blue_offset = vinfo.blue.offset;
    fbinfo.blue_length = vinfo.blue.length;
    fbinfo.alpha_offset = vinfo.transp.offset;
    fbinfo.alpha_length = vinfo.transp.length;

    /* HACK: for several of our 3d cores a specific alignment
     * is required so the start of the fb may not be an integer number of lines
     * from the base.  As a result we are storing the additional offset in
     * xoffset. This is not the correct usage for xoffset, it should be added
     * to each line, not just once at the beginning */
    offset = vinfo.xoffset * bytespp;

    offset += vinfo.xres * vinfo.yoffset * bytespp;

    if(writex(fd, &fbinfo, sizeof(fbinfo))) goto done;

    lseek(fb, offset, SEEK_SET);
    for(i = 0; i < fbinfo.size; i += 256) {
      if(readx(fb, &x, 256)) goto done;
      if(writex(fd, &x, 256)) goto done;
    }

    if(readx(fb, &x, fbinfo.size % 256)) goto done;
    if(writex(fd, &x, fbinfo.size % 256)) goto done;

done:
    if(fb >= 0) close(fb);
    close(fd);
}
开发者ID:2fast4u88,项目名称:oxygen_system_core,代码行数:55,代码来源:framebuffer_service.c

示例12: rt_I2C_write

/*******************************************************************************
* Function Name  : rt_I2C_write
* Description    : 向I2C E2PROM 地址中写入一个字节 外部函数
* Input          : address 地址 info 数据
* Output         : None
* Return         : None
*******************************************************************************/
void rt_I2C_write(unsigned char address,unsigned char info)

{
  start();
  writex(0xa0);
  clock();
  writex(address);
  clock();
  writex(info);
  clock();
  stop();
  Delay();
}
开发者ID:TIMCHENY,项目名称:STM32F107Board-rttproject,代码行数:20,代码来源:I2C.c

示例13: sync_start_readtime

static int sync_start_readtime(int fd, const char *path)
{
    syncmsg msg;
    int len = strlen(path);

    msg.req.id = ID_STAT;
    msg.req.namelen = htoll(len);

    if(writex(fd, &msg.req, sizeof(msg.req)) ||
       writex(fd, path, len)) {
        return -1;
    }

    return 0;
}
开发者ID:phybio,项目名称:adb,代码行数:15,代码来源:file_sync_client.c

示例14: main

int main(int argc, char **argv) {
	struct chunk c;
	off_t a, b = 0;
	int fin, fout;

	if (argc != 3) {
		fprintf(stderr, "usage: mksparse <infile> <outfile>");
		return -1;
	}

	if ((fin = open(argv[1], O_RDONLY)) < 0) {
		fprintf(stderr, "error: cannot open '%s' for reading\n", argv[1]);
		return -1;
	}

	if (!strcmp(argv[2], "-")) {
		fout = 1;
	} else if ((fout = open(argv[2], O_WRONLY | O_CREAT, 0600)) < 0) {
		fprintf(stderr, "error: cannot open '%s' for writing\n", argv[2]);
		return -1;
	}

	while ((a = lseek(fin, b, SEEK_DATA)) >= 0) {
		b = lseek(fin, a, SEEK_HOLE);
		c.start = a;
		c.length = b - a;
		if (lseek(fin, a, SEEK_SET) != a)
			goto fail;
		if (writex(fout, &c, sizeof(c)))
			goto fail;
		if (copyx(fin, fout, c.length, buffer, sizeof(buffer)))
			goto fail;
		/* fprintf(stderr, "%lu bytes at %lu\n", c.length, c.start); */
	}

	c.start = c.length = 0;
	if (writex(fout, &c, sizeof(c)))
		goto fail;

	if (close(fout))
		goto fail;

	return 0;

fail:
	fprintf(stderr, "error: %s\n", strerror(errno));
	return -1;
}
开发者ID:jaynes,项目名称:sparse,代码行数:48,代码来源:mksparse.c

示例15: DrawMenu

void DrawMenu(char items[][30], int maxitems, int select)
{
	int i,w,p,h;

	ClearScreen();

	/*** Draw Title Centred ***/

	p = (480 - (maxitems * font_height)) / 2 + 10;

	for( i = 0; i < maxitems; i++ )
	{
		w = CentreTextPosition(items[i]);
		h = GetTextWidth(items[i]);

/*		if ( i == select )
			writex( w, p, h, font_height, items[i], blit_lookup_inv );
		else
			writex( w, p, h, font_height, items[i], blit_lookup );*/

			writex( w, p, h, font_height, items[i], i == select );

		p += font_height;
	}

	SetScreen();
}
开发者ID:feraligatr,项目名称:fceugx,代码行数:27,代码来源:info.c


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