1/** \file 2 * \brief Simple test to check functionality of fscanf 3 */ 4 5/* 6 * Copyright (c) 2010, 2011, ETH Zurich. 7 * All rights reserved. 8 * 9 * This file is distributed under the terms in the attached LICENSE file. 10 * If you do not find this file, copies can be found by writing to: 11 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group. 12 */ 13 14#include <stdio.h> 15#include <barrelfish/barrelfish.h> 16#include <vfs/vfs.h> 17#include <errno.h> 18 19int main(int argc, char *argv[]) 20{ 21 errval_t err; 22 23 vfs_init(); 24 25 err = vfs_mkdir("/filetests"); 26 if (err_is_fail(err)) { 27 USER_PANIC_ERR(err, "vfs_mkdir failed"); 28 } 29 30 /* Create a file with a lot of data */ 31 FILE *fh = fopen("/filetests/fscanf_test.dat", "w"); 32 if (!fh) { 33 USER_PANIC("fopen failed (%d)", errno); 34 } 35 36 // Write various datatypes 37 fprintf(fh, "a %d\n", 1234); 38 fprintf(fh, "b %x\n", 1234); 39 fprintf(fh, "c %ld\n", 1234567890UL); 40 41 fclose(fh); 42 43 /* Read out the data in chunks */ 44 fh = fopen("/filetests/fscanf_test.dat", "r"); 45 if (!fh) { 46 USER_PANIC("fopen failed (%d)", errno); 47 } 48 49 // Read the various datatypes 50 int val, r; 51 r = fscanf(fh, "a %d\n", &val); 52 assert(r == 1); 53 if(val != 1234) { 54 USER_PANIC("fscanf read wrong value %d != 1234", val); 55 } 56 r = fscanf(fh, "b %x\n", &val); 57 assert(r == 1); 58 if(val != 1234) { 59 USER_PANIC("fscanf read wrong value %d != 1234", val); 60 } 61 long lval; 62 r = fscanf(fh, "c %ld\n", &lval); 63 assert(r == 1); 64 if(lval != 1234567890UL) { 65 USER_PANIC("fscanf read wrong value %ld != 1234567890", lval); 66 } 67 68 fclose(fh); 69 printf("client done\n"); 70 return 0; 71} 72