libite 2.6.1
erasef.c
Go to the documentation of this file.
1/* Formatted erase()
2 *
3 * Copyright (c) 2021 Joachim Wiberg <troglobit@gmail.com>
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
24
25#include <errno.h>
26#include <stdio.h>
27#include <stdarg.h>
28#include <stdlib.h>
29#include <unistd.h>
30
31#include "lite.h"
32
44int erasef(const char *fmt, ...)
45{
46 va_list ap;
47 char *file;
48 int len;
49
50 va_start(ap, fmt);
51 len = vsnprintf(NULL, 0, fmt, ap);
52 va_end(ap);
53
54 file = alloca(len + 1);
55 if (!file) {
56 errno = ENOMEM;
57 return -1;
58 }
59
60 va_start(ap, fmt);
61 vsnprintf(file, len + 1, fmt, ap);
62 va_end(ap);
63
64 return erase(file);
65}
66
int erasef(const char *fmt,...)
Definition erasef.c:44