C++ (Cpp) memcmp Examples

C++ (Cpp) memcmp - 30 examples found. These are the top rated real world C++ (Cpp) examples of memcmp extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
static bool
ioat_compare_ok(struct test_transaction *tx)
{
    struct ioat_test *test;
    char *dst, *src;
    uint32_t i, j;

    test = tx->test;

    for (i = 0; i < tx->depth; i++) {
        dst = tx->buf[2 * i + 1];
        src = tx->buf[2 * i];

        if (test->testkind == IOAT_TEST_FILL) {
            for (j = 0; j < tx->length; j += sizeof(uint64_t)) {
                if (memcmp(src, &dst[j],
                           MIN(sizeof(uint64_t), tx->length - j))
                        != 0)
                    return (false);
            }
        } else if (test->testkind == IOAT_TEST_DMA) {
            if (memcmp(src, dst, tx->length) != 0)
                return (false);
        } else if (test->testkind == IOAT_TEST_RAW_DMA) {
            if (test->raw_write)
                dst = test->raw_vtarget;
            dump_hex(dst, tx->length / 32);
        }
    }
    return (true);
}
static int get_process_info(pid_t tid, pid_t* out_pid, uid_t* out_uid, uid_t* out_gid) {
    char path[64];
    snprintf(path, sizeof(path), "/proc/%d/status", tid);

    FILE* fp = fopen(path, "r");
    if (!fp) {
        return -1;
    }

    int fields = 0;
    char line[1024];
    while (fgets(line, sizeof(line), fp)) {
        size_t len = strlen(line);
        if (len > 6 && !memcmp(line, "Tgid:\t", 6)) {
            *out_pid = atoi(line + 6);
            fields |= 1;
        } else if (len > 5 && !memcmp(line, "Uid:\t", 5)) {
            *out_uid = atoi(line + 5);
            fields |= 2;
        } else if (len > 5 && !memcmp(line, "Gid:\t", 5)) {
            *out_gid = atoi(line + 5);
            fields |= 4;
        }
    }
    fclose(fp);
    return fields == 7 ? 0 : -1;
}
Example #3
0
// Validates the RIFF container (if detected) and skips over it.
// If a RIFF container is detected, returns:
//     VP8_STATUS_BITSTREAM_ERROR for invalid header,
//     VP8_STATUS_NOT_ENOUGH_DATA for truncated data if have_all_data is true,
// and VP8_STATUS_OK otherwise.
// In case there are not enough bytes (partial RIFF container), return 0 for
// *riff_size. Else return the RIFF size extracted from the header.
static VP8StatusCode ParseRIFF(const uint8_t** const data,
                               size_t* const data_size, int have_all_data,
                               size_t* const riff_size) {
    assert(data != NULL);
    assert(data_size != NULL);
    assert(riff_size != NULL);

    *riff_size = 0;  // Default: no RIFF present.
    if (*data_size >= RIFF_HEADER_SIZE && !memcmp(*data, "RIFF", TAG_SIZE)) {
        if (memcmp(*data + 8, "WEBP", TAG_SIZE)) {
            return VP8_STATUS_BITSTREAM_ERROR;  // Wrong image file signature.
        } else {
            const uint32_t size = get_le32(*data + TAG_SIZE);
            // Check that we have at least one chunk (i.e "WEBP" + "VP8?nnnn").
            if (size < TAG_SIZE + CHUNK_HEADER_SIZE) {
                return VP8_STATUS_BITSTREAM_ERROR;
            }
            if (size > MAX_CHUNK_PAYLOAD) {
                return VP8_STATUS_BITSTREAM_ERROR;
            }
            if (have_all_data && (size > *data_size - CHUNK_HEADER_SIZE)) {
                return VP8_STATUS_NOT_ENOUGH_DATA;  // Truncated bitstream.
            }
            // We have a RIFF container. Skip it.
            *riff_size = size;
            *data += RIFF_HEADER_SIZE;
            *data_size -= RIFF_HEADER_SIZE;
        }
    }
    return VP8_STATUS_OK;
}
static void
foobar_typefind (GstTypeFind * tf, gpointer unused)
{
    guint8 *data;

    data = gst_type_find_peek (tf, 0, 10);
    fail_unless (data != NULL);
    fail_unless (memcmp (data, vorbisid, 10) == 0);

    data = gst_type_find_peek (tf, 0, 20);
    fail_unless (data != NULL);
    fail_unless (memcmp (data, vorbisid, 20) == 0);

    data = gst_type_find_peek (tf, 0, 30);
    fail_unless (data != NULL);
    fail_unless (memcmp (data, vorbisid, 30) == 0);

    fail_unless (gst_type_find_peek (tf, 0, 31) == NULL);
    fail_unless (gst_type_find_peek (tf, 1, 30) == NULL);
    fail_unless (gst_type_find_peek (tf, 25, 6) == NULL);

    data = gst_type_find_peek (tf, 1, 29);
    fail_unless (data != NULL);
    fail_unless (memcmp (data, vorbisid + 1, 29) == 0);

    data = gst_type_find_peek (tf, 25, 4);
    fail_unless (data != NULL);
    fail_unless (memcmp (data, vorbisid + 25, 4) == 0);

    fail_unless (gst_type_find_peek (tf, -1, 29) == NULL);
    fail_unless (gst_type_find_peek (tf, -1, 1) == NULL);
    fail_unless (gst_type_find_peek (tf, -1, 0) == NULL);

    gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FOOBAR_CAPS);
}
Example #5
0
PRIVATE size_t parse_Transmission_response(void *ptr, size_t size, size_t nmemb, void *data) {
    size_t        line_len = size * nmemb;
    const char   *line = ptr;
    WebData      *mem = data;
    const char   *session_key = "X-Transmission-Session-Id: ";
    const size_t  key_len = strlen( session_key );
    char         *tmp = NULL;
    int           content_length = 0;


    if( (line_len >= key_len) && !memcmp(line, session_key, key_len) ) {
        const char * begin = line + key_len;
        const char * end = begin;
        while( !isspace( *end ) ) {
            ++end;
        }
        am_free( gSessionID );
        gSessionID = NULL;
        gSessionID = am_strndup( begin, end-begin );
        /* parse header for Content-Length to allocate correct size for data->response->data */
    } else if(line_len >= 15 && !memcmp(line, "Content-Length:", 15)) {
        tmp = getRegExMatch("Content-Length:\\s(\\d+)", line, 1);
        if(tmp != NULL) {
            dbg_printf(P_INFO2, "Content-Length: %s", tmp);
            content_length = atoi(tmp);
            if(content_length > 0) {
                mem->content_length = content_length;
                mem->response->data = am_realloc(mem->response->data, content_length + 1);
            }
            am_free(tmp);
        }
    }

    return line_len;
}
Example #6
0
int Wave::WavHdrRead() {
    std::ifstream fin;
    long cursor, len;

    fin.open(wavename, std::ios::binary);
    if (!fin) {
        std::cerr << "ファイルを開けませんでした." << std::endl;
        return -1;
    }
    // ヘッダ情報
    fin.read((char *)&header, sizeof(header));
    if (fin.bad()) {
        std::cerr << "読み込みエラー" << std::endl;
        exit(0);
    }

    // WAVE ヘッダ情報
    if (memcmp(header.hdrWave, STR_WAVE, 4) != 0) {
        std::cerr << "'WAVE' が無い." << std::endl;
        return -1;
    }

    if (memcmp(&header.hdrRiff, STR_RIFF, 4) != 0) {
        std::cerr << "'RIFF' フォーマットでない." << std::endl;
        return -1;
    }

    // 4Byte これ以降のバイト数 = (ファイルサイズ - 8)(Byte)
    len = header.sizeOfFile;

    // チャンク情報
    while (!fin.eof()) {
        fin.read((char *)&chunk, sizeof(chunk));
        if (fin.bad()) {
            std::cerr << "読み込みエラー" << std::endl;
            exit(0);
        }

        if (memcmp(chunk.hdrFmtData, STR_fmt, sizeof chunk.hdrFmtData) == 0) {
            len = chunk.sizeOfFmtData;
            cursor = fin.tellg();
            if (ReadfmtChunk(&fin) != 0) return -1;
            samplesPerSec = wavfmtpcm.samplesPerSec;
            bitsPerSample = wavfmtpcm.bitsPerSample;
            channels = wavfmtpcm.channels;
            bytesPerSec = wavfmtpcm.bytesPerSec;
            fin.seekg(cursor + len, std::ios_base::beg);
        } else if (memcmp(chunk.hdrFmtData, STR_data, 4) == 0) {
            sizeOfData = chunk.sizeOfFmtData;
            posOfData = fin.tellg();
            fin.seekg(sizeOfData + posOfData - 4, std::ios_base::beg);
        } else {
            len = chunk.sizeOfFmtData;
            cursor = fin.tellg();
            fin.seekg(cursor + len, std::ios::beg);
        }
    }

    return 0;
}