示例#1
0
文件: libwakelock.c 项目: guhl/mce
/** Helper for writing to sysfs files
 */
static void lwl_write_file(const char *path, const char *data)
{
	int file;

	lwl_debug(path, " << ", data, NULL);

	if( (file = TEMP_FAILURE_RETRY(open(path, O_WRONLY))) == -1 ) {
		lwl_debug(path, ": open: ", strerror(errno), "\n", NULL);
	} else {
		int size = strlen(data);
		errno = 0;
		if( TEMP_FAILURE_RETRY(write(file, data, size)) != size ) {
			lwl_debug(path, ": write: ", strerror(errno),
				  "\n", NULL);
		}
		TEMP_FAILURE_RETRY(close(file));
	}
}
示例#2
0
文件: libwakelock.c 项目: guhl/mce
/** Helper for checking if wakelock interface is supported
 */
static int lwl_enabled(void)
{
	static int checked = 0, enabled = 0;

	if( !checked ) {
		checked = 1, enabled = !access(lwl_lock_path, F_OK);
		lwl_debug(enabled ? "enabled" : "disabled", "\n", NULL);
	}

	return enabled;
}
示例#3
0
/** Write text to a sysfs file
 *
 * @param path file to write
 * @param data text to write
 * @param size lenght of text
 *
 * @return true if write was successful, false otherwise
 */
static bool
lwl_write_text(const char *path, const char *data, int size)
{
	bool res = false;
	int  fd  = -1;

	if( !path || !data || size <= 0 )
		goto cleanup;

	lwl_debug(path, " << ", data, "\n", NULL);

	if( (fd = open(path, O_WRONLY)) == -1 )
		goto cleanup;

	if( write(fd, data, size) == -1 )
		goto cleanup;

	res = true;

cleanup:
	if( fd != -1 ) close(fd);

	return res;
}