mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
Add virFileTouch for creating empty files
Add a virFileTouch API which ensures that a file will always exist, even if zero length * src/util/virfile.c, src/util/virfile.h, src/libvirt_private.syms: Introduce virFileTouch
This commit is contained in:
parent
6fba577e50
commit
ef7efbc6ef
@ -1174,6 +1174,7 @@ virFileDirectFdNew;
|
|||||||
virFileFclose;
|
virFileFclose;
|
||||||
virFileFdopen;
|
virFileFdopen;
|
||||||
virFileRewrite;
|
virFileRewrite;
|
||||||
|
virFileTouch;
|
||||||
|
|
||||||
|
|
||||||
# virkeycode.h
|
# virkeycode.h
|
||||||
|
@ -390,3 +390,24 @@ cleanup:
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int virFileTouch(const char *path, mode_t mode)
|
||||||
|
{
|
||||||
|
int fd = -1;
|
||||||
|
|
||||||
|
if ((fd = open(path, O_WRONLY | O_CREAT, mode)) < 0) {
|
||||||
|
virReportSystemError(errno, _("cannot create file '%s'"),
|
||||||
|
path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (VIR_CLOSE(fd) < 0) {
|
||||||
|
virReportSystemError(errno, _("cannot save file '%s'"),
|
||||||
|
path);
|
||||||
|
VIR_FORCE_CLOSE(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@ -74,4 +74,6 @@ int virFileRewrite(const char *path,
|
|||||||
virFileRewriteFunc rewrite,
|
virFileRewriteFunc rewrite,
|
||||||
void *opaque);
|
void *opaque);
|
||||||
|
|
||||||
|
int virFileTouch(const char *path, mode_t mode);
|
||||||
|
|
||||||
#endif /* __VIR_FILES_H */
|
#endif /* __VIR_FILES_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user