Scrap writerune(), introducing fputrune()
Interface and function as proposed by cls. Code is also shorter, everything else analogous to fgetrune().
This commit is contained in:
		
							
								
								
									
										27
									
								
								libutf/fputrune.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								libutf/fputrune.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| /* See LICENSE file for copyright and license details. */ | ||||
| #include <errno.h> | ||||
| #include <stdio.h> | ||||
| #include <stdlib.h> | ||||
| #include <string.h> | ||||
|  | ||||
| #include "../utf.h" | ||||
|  | ||||
| int | ||||
| fputrune(const Rune *r, FILE *fp) | ||||
| { | ||||
| 	char buf[UTFmax]; | ||||
|  | ||||
| 	return fwrite(buf, runetochar(buf, r), 1, fp); | ||||
| } | ||||
|  | ||||
| int | ||||
| efputrune(const Rune *r, FILE *fp, const char *file) | ||||
| { | ||||
| 	int ret; | ||||
|  | ||||
| 	if ((ret = fputrune(r, fp)) < 0) { | ||||
| 		fprintf(stderr, "fputrune %s: %s\n", file, strerror(errno)); | ||||
| 		exit(1); | ||||
| 	} | ||||
| 	return ret; | ||||
| } | ||||
| @@ -1,23 +0,0 @@ | ||||
| /* See LICENSE file for copyright and license details. */ | ||||
| #include <errno.h> | ||||
| #include <stdio.h> | ||||
| #include <string.h> | ||||
| #include <stdlib.h> | ||||
|  | ||||
| #include "../utf.h" | ||||
|  | ||||
| void | ||||
| writerune(const char *file, FILE *fp, Rune *r) | ||||
| { | ||||
| 	char buf[UTFmax]; | ||||
| 	int n; | ||||
|  | ||||
| 	if ((n = runetochar(buf, r)) > 0) { | ||||
| 		fwrite(buf, n, 1, fp); | ||||
| 		if (ferror(fp)) { | ||||
| 			fprintf(stderr, "%s: write error: %s\n", | ||||
| 				file, strerror(errno)); | ||||
| 			exit(1); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user