OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [userland/] [route/] [lib/] [util.c] - Blame information for rev 1767

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 745 simons
/* Copyright 1998 by Andi Kleen. Subject to the GPL. */
2
/* $Id: util.c,v 1.1 2002-03-17 19:58:53 simons Exp $ */
3
#include <stdio.h>
4
#include <stdlib.h>
5
#include <string.h>
6
#include <sys/utsname.h>
7
 
8
#include "util.h"
9
 
10
 
11
static void oom(void)
12
{
13
    fprintf(stderr, "out of virtual memory\n");
14
    exit(2);
15
}
16
 
17
void *xmalloc(size_t sz)
18
{
19
    void *p = calloc(sz, 1);
20
    if (!p)
21
        oom();
22
    return p;
23
}
24
 
25
void *xrealloc(void *oldp, size_t sz)
26
{
27
    void *p = realloc(oldp, sz);
28
    if (!p)
29
        oom();
30
    return p;
31
}
32
 
33
int kernel_version(void)
34
{
35
    struct utsname uts;
36
    int major, minor, patch;
37
 
38
    if (uname(&uts) < 0)
39
        return -1;
40
    if (sscanf(uts.release, "%d.%d.%d", &major, &minor, &patch) != 3)
41
        return -1;
42
    return KRELEASE(major, minor, patch);
43
}
44
 
45
 
46
/* Like strncpy but make sure the resulting string is always 0 terminated. */
47
char *safe_strncpy(char *dst, const char *src, size_t size)
48
{
49
    dst[size-1] = '\0';
50
    return strncpy(dst,src,size-1);
51
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.