Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Utorok, 16. júl 2024

Súbor: [Platon] / cpdf / utils.c (stiahnutie)

Revízia 1.12, Tue Feb 11 20:10:30 2003 UTC (21 years, 5 months ago) by lynx


Zmeny od 1.11: +3 -2 [lines]

improved reading and working with objects
remove read bug from get_startxref() if PDF uses \r\n as a newline.
better reading streams.
AND MANY MANY MORE! :))) but you still cant use it :-D

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "parse.h"
void *xmalloc(size_t size)
{
    void *p;
    p = malloc(size);
    if (!p) {
        fprintf(stderr, "malloc: %s", strerror(errno));
        exit(errno);
    }
    return p;
}

void *xcalloc(size_t nmemb, size_t size)
{
    void *p;
    p = xmalloc(nmemb * size);
    memset(p, '\0', nmemb * size);
    return p;
}
char *resize(char *ptr, size_t size)
{
/*    char *ret;
    if (!ptr)
        ret = (char *) xcalloc(size, 1);
    else {
        ret = (char *) xcalloc(size, 1);
        memcpy(ret, ptr, size);
        free(ptr);
    }
    return ret;*/
    return (char *) realloc(ptr, size);
}

char *fget(char *s, int size, FILE * stream)
{
    int i;
    char c;
    for (i = 0; i < size; i++) {
        s[i] = fgetc(stream);
        if (s[i] == '\n' || s[i] == '\r') {
            s[i] = '\n';
            s[i + 1] = '\0';
            do {
                c = fgetc(stream);
            } while (c == '\n' || c == '\r');
            fseek(stream, -1, SEEK_CUR);
            break;
        }
    }
    return s;
}

char *strnstr(const char *haystack, char *needle, size_t size)
{
    char *max;
    size_t len = strlen(needle);
    if (!haystack || !needle || !size)
        return NULL;
    for (max = (char *) (haystack + size - len); haystack < max;
         haystack++)
        if (*haystack == *needle)
            if (!strncmp(haystack, needle, len))
                return (char *) haystack;
    return NULL;
}

Platon Group <platon@platon.sk> http://platon.sk/
Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok