Example #1
0
/* given a pointer to a mfu_param_path, pack into the specified
 * buffer and update the pointer to point to next free byte */
static void mfu_pack_param(char** pptr, const mfu_param_path* param)
{
    /* pack the original path */
    mfu_pack_str(pptr, param->orig);

    /* pack the reduced path and stat data */
    mfu_pack_str(pptr, param->path);

    /* pack the reduced path stat data */
    if (param->path != NULL) {
        if (param->path_stat_valid) {
            /* set flag to indicate that we have stat data */
            mfu_pack_uint32(pptr, 1);
    
            /* pack stat data */
            mfu_pack_stat(pptr, &param->path_stat);
        } else {
            /* set flag to indicate that we don't have stat data */
            mfu_pack_uint32(pptr, 0);
        }
    }

    /* pack the target path and stat data */
    mfu_pack_str(pptr, param->target);

    /* pack the target stat data */
    if (param->target != NULL) {
        if (param->target_stat_valid) {
            /* set flag to indicate that we have stat data */
            mfu_pack_uint32(pptr, 1);

            /* pack stat data */
            mfu_pack_stat(pptr, &param->target_stat);
        } else {
            /* set flag to indicate that we don't have stat data */
            mfu_pack_uint32(pptr, 0);
        }
    }

    return;
}
Example #2
0
/* given a pointer to a string, which may be the NULL pointer,
 * pack the string into the specified buffer and update the
 * pointer to point to next free byte */
static void mfu_pack_str(char** pptr, const char* str)
{
    /* check whether we have a string */
    if (str != NULL) {
        /* set flag to indicate that we have string */
        mfu_pack_uint32(pptr, 1);

        /* get pointer to start of buffer */
        char* ptr = *pptr;

        /* copy in string */
        size_t len = strlen(str) + 1;
        strncpy(ptr, str, len);

        /* update caller's pointer */
        *pptr += len;
    } else {
        /* set flag to indicate that we don't have str */
        mfu_pack_uint32(pptr, 0);
    }
}
Example #3
0
/* pack element into buffer and return number of bytes written */
static size_t list_elem_pack2(void* buf, int detail, uint64_t chars, const elem_t* elem)
{
    /* set pointer to start of buffer */
    char* start = (char*) buf;
    char* ptr = start;

    /* copy in detail flag */
    mfu_pack_uint32(&ptr, (uint32_t) detail);

    /* copy in length of file name field */
    mfu_pack_uint32(&ptr, (uint32_t) chars);

    /* copy in file name */
    char* file = elem->file;
    strcpy(ptr, file);
    ptr += chars;

    if (detail) {
        /* copy in fields */
        mfu_pack_uint64(&ptr, elem->mode);
        mfu_pack_uint64(&ptr, elem->uid);
        mfu_pack_uint64(&ptr, elem->gid);
        mfu_pack_uint64(&ptr, elem->atime);
        mfu_pack_uint64(&ptr, elem->atime_nsec);
        mfu_pack_uint64(&ptr, elem->mtime);
        mfu_pack_uint64(&ptr, elem->mtime_nsec);
        mfu_pack_uint64(&ptr, elem->ctime);
        mfu_pack_uint64(&ptr, elem->ctime_nsec);
        mfu_pack_uint64(&ptr, elem->size);
    }
    else {
        /* just have the file type */
        mfu_pack_uint32(&ptr, elem->type);
    }

    size_t bytes = (size_t)(ptr - start);
    return bytes;
}