예제 #1
0
파일: buflib.c 프로젝트: albb0920/rockbox
/*
 * Allocate all available (as returned by buflib_available()) memory and return
 * a handle to it
 *
 * This grabs a lock which can only be unlocked by buflib_free() or
 * buflib_shrink(), to protect from further allocations (which couldn't be
 * serviced anyway).
 */
int
buflib_alloc_maximum(struct buflib_context* ctx, const char* name, size_t *size, struct buflib_callbacks *ops)
{
    /* limit name to 16 since that's what buflib_available() accounts for it */
    char buf[16];

    *size = buflib_available(ctx);
    if (*size <= 0) /* OOM */
        return -1;

    strlcpy(buf, name, sizeof(buf));

    return buflib_alloc_ex(ctx, *size, buf, ops);
}
예제 #2
0
/*
 * Allocate all available (as returned by buflib_available()) memory and return
 * a handle to it
 *
 * This grabs a lock which can only be unlocked by buflib_free() or
 * buflib_shrink(), to protect from further allocations (which couldn't be
 * serviced anyway).
 */
int
buflib_alloc_maximum(struct buflib_context* ctx, const char* name, size_t *size, struct buflib_callbacks *ops)
{
    int handle;

    /* limit name to 16 since that's what buflib_available() accounts for it */
    char buf[16];
    *size = buflib_available(ctx);
    strlcpy(buf, name, sizeof(buf));
    handle = buflib_alloc_ex(ctx, *size, buf, ops);

    if (handle > 0) /* shouldn't happen ?? */
        ctx->handle_lock = handle;
    
    return handle;
}