util: add virFileReadHeaderQuiet wrapper around virFileReadHeaderFD

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
Paolo Bonzini 2017-12-12 16:23:40 +01:00 committed by Jiri Denemark
parent 8d424f1b23
commit 40fc85e796
3 changed files with 22 additions and 0 deletions

View File

@ -1760,6 +1760,7 @@ virFileReadAll;
virFileReadAllQuiet;
virFileReadBufQuiet;
virFileReadHeaderFD;
virFileReadHeaderQuiet;
virFileReadLimFD;
virFileReadLink;
virFileReadValueBitmap;

View File

@ -1367,6 +1367,25 @@ virFileReadHeaderFD(int fd, int maxlen, char **buf)
}
int
virFileReadHeaderQuiet(const char *path,
int maxlen,
char **buf)
{
int fd;
int len;
fd = open(path, O_RDONLY);
if (fd < 0)
return -1;
len = virFileReadHeaderFD(fd, maxlen, buf);
VIR_FORCE_CLOSE(fd);
return len;
}
/* A wrapper around saferead_lim that maps a failure due to
exceeding the maximum size limitation to EOVERFLOW. */
int

View File

@ -131,6 +131,8 @@ int virFileDeleteTree(const char *dir);
int virFileReadHeaderFD(int fd, int maxlen, char **buf)
ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(3);
int virFileReadHeaderQuiet(const char *path, int maxlen, char **buf)
ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
int virFileReadLimFD(int fd, int maxlen, char **buf)
ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(3);
int virFileReadAll(const char *path, int maxlen, char **buf)