File: Mallocs.c

package info (click to toggle)
fvwm95 2.0.43ba-22
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 5,904 kB
  • ctags: 4,760
  • sloc: ansic: 46,436; makefile: 1,589; sh: 780; perl: 328
file content (64 lines) | stat: -rw-r--r-- 1,958 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* FvwmWinList Module for Fvwm. 
 *
 *  Copyright 1994,  Mike Finger (mfinger@mermaid.micro.umn.edu or
 *                               Mike_Finger@atk.com)
 *
 * The author makes not guarantees or warantees, either express or
 * implied.  Feel free to use any contained here for any purpose, as long
 * and this and any other applicible copyrights are kept intact.

 * The functions in this source file that are based on part of the FvwmIdent
 * module for Fvwm are noted by a small copyright atop that function, all others
 * are copyrighted by Mike Finger.  For those functions modified/used, here is
 * the full, original copyright:
 *
 * Copyright 1994, Robert Nation and Nobutaka Suzuki.
 * No guarantees or warantees or anything
 * are provided or implied in any way whatsoever. Use this program at your
 * own risk. Permission to use this program for any purpose is given,
 * as long as the copyright is kept intact. */

#include <FVWMconfig.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <sys/time.h>
#include <fvwm/fvwmlib.h>

#ifdef BROKEN_SUN_HEADERS
#include "../../fvwm/sun_headers.h"
#endif

#ifdef NEEDS_ALPHA_HEADER
#include "../../fvwm/alpha_header.h"
#endif /* NEEDS_ALPHA_HEADER */

extern char *Module;

/******************************************************************************
  saferealloc - safely reallocate memory or exit if fails. (Doesn't work right)
******************************************************************************/
char *saferealloc(char *ptr, int length)
{
char *newptr;

  if(length <=0) length=1;

  newptr=realloc(ptr,length);
    if (ptr == (char *)0) {
      fprintf(stderr,"%s:realloc failed",Module);
      exit(1);
    }
  return ptr;
}

void UpdateString(char **string,char *value)
{
  if (value==NULL) return;
  if (*string==NULL) *string=safemalloc(strlen(value)+1);
  else *string=(char *)realloc(*string,strlen(value)+1);
  strcpy(*string,value);
}