PAPI  5.7.0.0
pscanf.h
Go to the documentation of this file.
1 /* This file was taken from the tacc_stats utility, which is distributed
2  * under a GPL license.
3  */
4 #ifndef _PSCANF_H_
5 #define _PSCANF_H_
6 #include <stdio.h>
7 #include <stdarg.h>
8 
9 __attribute__((format(scanf, 2, 3)))
10  static inline int pscanf(const char *path, const char *fmt, ...)
11 {
12  int rc = -1;
13  FILE *file = NULL;
14  char file_buf[4096];
15  va_list arg_list;
17 
18  file = fopen(path, "r");
19  if (file == NULL)
20  goto out;
21  setvbuf(file, file_buf, _IOFBF, sizeof(file_buf));
22 
23  rc = vfscanf(file, fmt, arg_list);
24 
25  out:
26  if (file != NULL)
27  fclose(file);
29  return rc;
30 }
31 
32 #endif
rc
Definition: pscanf.h:23
va_start(arg_list, fmt)
va_list arg_list
Definition: pscanf.h:15
const char FILE * file
Definition: pscanf.h:13
const char * fmt
Definition: pscanf.h:10
char file_buf[4096]
Definition: pscanf.h:14
va_end(arg_list)
setvbuf(file, file_buf, _IOFBF, sizeof(file_buf))
__attribute__((format(scanf, 2, 3))) static inline int pscanf(const char *path