kernel: restore fprintf() for printing to vfs nodes (character devices)
This commit is contained in:
parent
16ae59895c
commit
ced8bcba96
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <kernel/types.h>
|
||||
|
||||
__attribute__((format(__printf__,1,2)))
|
||||
@ -7,3 +8,4 @@ extern int printf(const char *fmt, ...);
|
||||
extern size_t (*printf_output)(size_t, uint8_t *);
|
||||
__attribute__((format(__printf__,3,4)))
|
||||
extern int snprintf(char * str, size_t size, const char * format, ...);
|
||||
extern size_t xvasprintf(int (*callback)(void *, char), void * userData, const char * fmt, va_list args);
|
||||
|
@ -151,3 +151,4 @@ void map_vfs_directory(const char *);
|
||||
|
||||
int make_unix_pipe(fs_node_t ** pipes);
|
||||
|
||||
int fprintf(fs_node_t * f, const char * fmt, ...);
|
||||
|
@ -38,6 +38,26 @@ hashmap_t * fs_types = NULL;
|
||||
|
||||
#define debug_print(x, ...) do { if (0) {printf("vfs.c [%s] ", #x); printf(__VA_ARGS__); printf("\n"); } } while (0)
|
||||
|
||||
static int cb_printf(void * user, char c) {
|
||||
fs_node_t * f = user;
|
||||
write_fs(f, 0, 1, (uint8_t*)&c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write printf output to a simple file node.
|
||||
*
|
||||
* The file node, f, must be a simple character device that
|
||||
* allows repeated writes of a single byte without an incrementing
|
||||
* offset, such as a serial port or TTY.
|
||||
*/
|
||||
int fprintf(fs_node_t * f, const char * fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int out = xvasprintf(cb_printf, f, fmt, args);
|
||||
va_end(args);
|
||||
return out;
|
||||
}
|
||||
|
||||
int has_permission(fs_node_t * node, int permission_bit) {
|
||||
if (!node) return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user