static char *mkpath(const char *path, const char *name)
{
char *n;
- int len1 = strlen(path);
- int len2 = strlen(name);
+ size_t len1 = strlen(path);
+ size_t len2 = strlen(name);
- n = malloc(len1 + len2 + 2);
- if (!n) {
- sys_errmsg("cannot allocate %d bytes", len1 + len2 + 2);
- return NULL;
- }
+ n = xmalloc(len1 + len2 + 2);
memcpy(n, path, len1);
if (n[len1 - 1] != '/')
{
struct libmtd *lib;
- lib = calloc(1, sizeof(struct libmtd));
- if (!lib)
- return NULL;
+ lib = xzalloc(sizeof(*lib));
lib->offs64_ioctls = OFFS64_IOCTLS_UNKNOWN;
normsg("run torture test for PEB %d", eb);
patt_count = ARRAY_SIZE(patterns);
- buf = malloc(mtd->eb_size);
- if (!buf) {
- errmsg("cannot allocate %d bytes of memory", mtd->eb_size);
- return -1;
- }
+ buf = xmalloc(mtd->eb_size);
for (i = 0; i < patt_count; i++) {
err = mtd_erase(desc, mtd, fd, eb);
goto out_close;
}
- buf = malloc(mtd->eb_size);
- if (!buf) {
- sys_errmsg("cannot allocate %d bytes of memory", mtd->eb_size);
- goto out_close;
- }
+ buf = xmalloc(mtd->eb_size);
while (written < len) {
int rd = 0;
if (fd == -1)
return -1;
- pi->buf = malloc(PROC_MTD_MAX_LEN);
- if (!pi->buf) {
- sys_errmsg("cannot allocate %d bytes of memory",
- PROC_MTD_MAX_LEN);
- goto out_close;
- }
+ pi->buf = xmalloc(PROC_MTD_MAX_LEN);
ret = read(fd, pi->buf, PROC_MTD_MAX_LEN);
if (ret == -1) {
out_free:
free(pi->buf);
-out_close:
close(fd);
return -1;
}