1 /*
2  * tumble: build a PDF file from image files
3  *
4  * PDF routines
5  * Copyright 2001, 2002, 2003, 2017 Eric Smith <spacewar@gmail.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.  Note that permission is
10  * not granted to redistribute this program under the terms of any
11  * other version of the General Public License.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
21  */
22 
23 
24 #include <stdarg.h>
25 #include <stdbool.h>
26 #include <stdint.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 
31 #include "bitblt.h"
32 #include "pdf_util.h"
33 
34 
pdf_fatal(char * fmt,...)35 void pdf_fatal (char *fmt, ...)
36 {
37   va_list ap;
38 
39   va_start (ap, fmt);
40   vfprintf (stderr, fmt, ap);
41   va_end (ap);
42 
43   exit (2);
44 }
45 
46 
pdf_calloc(size_t nmemb,size_t size)47 void *pdf_calloc (size_t nmemb, size_t size)
48 {
49   void *m = calloc (nmemb, size);
50   if (! m)
51     pdf_fatal ("failed to allocate memory\n");
52   return (m);
53 }
54 
55 
pdf_strdup(char * s)56 char *pdf_strdup (char *s)
57 {
58   unsigned long len = strlen (s);
59   char *s2 = pdf_calloc (1, len + 1);
60   strcpy (s2, s);
61   return (s2);
62 }
63