Blame src/components/infiniband/pscanf.h

Packit 577717
/* This file was taken from the tacc_stats utility, which is distributed 
Packit 577717
 * under a GPL license.
Packit 577717
 */
Packit 577717
#ifndef _PSCANF_H_
Packit 577717
#define _PSCANF_H_
Packit 577717
#include <stdio.h>
Packit 577717
#include <stdarg.h>
Packit 577717
Packit 577717
__attribute__((format(scanf, 2, 3)))
Packit 577717
  static inline int pscanf(const char *path, const char *fmt, ...)
Packit 577717
{
Packit 577717
  int rc = -1;
Packit 577717
  FILE *file = NULL;
Packit 577717
  char file_buf[4096];
Packit 577717
  va_list arg_list;
Packit 577717
  va_start(arg_list, fmt);
Packit 577717
Packit 577717
  file = fopen(path, "r");
Packit 577717
  if (file == NULL)
Packit 577717
    goto out;
Packit 577717
  setvbuf(file, file_buf, _IOFBF, sizeof(file_buf));
Packit 577717
Packit 577717
  rc = vfscanf(file, fmt, arg_list);
Packit 577717
Packit 577717
 out:
Packit 577717
  if (file != NULL)
Packit 577717
    fclose(file);
Packit 577717
  va_end(arg_list);
Packit 577717
  return rc;
Packit 577717
}
Packit 577717
Packit 577717
#endif