Use direct open/write/close instead of stdlib calls for device IO
This commit is contained in:
		
							parent
							
								
									37941f6ba8
								
							
						
					
					
						commit
						aa8513ba84
					
				
					 1 changed files with 6 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -1,4 +1,5 @@
 | 
			
		|||
#include <dirent.h>
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
| 
						 | 
				
			
			@ -31,11 +32,11 @@ static char * powerstatefile = "/sys/power/state";
 | 
			
		|||
void
 | 
			
		||||
writefile(char *filepath, char *str)
 | 
			
		||||
{
 | 
			
		||||
	FILE *f;
 | 
			
		||||
	f = fopen(filepath, "w");
 | 
			
		||||
	if (f) {
 | 
			
		||||
		fprintf(f, "%s\n", str);
 | 
			
		||||
		fclose(f);
 | 
			
		||||
	int f;
 | 
			
		||||
	f = open(filepath, O_WRONLY);
 | 
			
		||||
	if (f != NULL) {
 | 
			
		||||
		write(f, str, strlen(str));
 | 
			
		||||
		close(f);
 | 
			
		||||
	} else {
 | 
			
		||||
		fprintf(stderr, "Couldn't open filepath <%s>\n", filepath);
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue