/** * Allocate a block of memory. * Fill it with zeroes. */ void *mem_alloc (mem_pool_t *m, size_t required) { void *p; p = mem_alloc_dirty (m, required); if (p && required > 0) memsetw (p, 0, required); return p; }
void do_fat_open(fs_entry_t *entry) { fat_fs_t *fat = (fat_fs_t *)entry->fs; entry->cache_data = mem_alloc_dirty(fat->pool, fat->bytes_per_sec); if (!entry->cache_data) { entry->fs->last_error = FS_ERR_NO_MEM; return; } entry->cache_size = fat->bytes_per_sec; do_fat_seek_start(entry); entry->fs->last_error = FS_ERR_OK; }
static fat_fs_entry_t *alloc_fs_entry(fat_fs_t *fat, unsigned name_size) { fat_fs_entry_t *e; e = mem_alloc(fat->pool, sizeof(fat_fs_entry_t)); if (!e) return 0; e->fs_entry.name = mem_alloc_dirty(fat->pool, name_size); if (!e->fs_entry.name) { mem_free(e); return 0; } e->fs_entry.fs = (fsif_t *)fat; return e; }
unsigned char *mem_strndup (mem_pool_t *m, const unsigned char *str, size_t len) { unsigned char *p; if (! str) return 0; len = strnlen (str, len); p = mem_alloc_dirty (m, len + 1); if (! p) return 0; memcpy (p, str, len); p [len] = 0; return p; }
unsigned char *mem_strdup (mem_pool_t *m, const unsigned char *str) { size_t len; unsigned char *p; if (! str) return 0; len = strlen (str); p = (unsigned char *)mem_alloc_dirty (m, len + 1); if (! p) return 0; memcpy (p, str, len + 1); return p; }