JWS-112 Bumping version of T-Coffee to version 11.00.8cbe486.
[jabaws.git] / binaries / src / tcoffee / t_coffee_source / km_coffee / km_util.c
1 /******************************COPYRIGHT NOTICE*******************************/
2 /*  (c) Centro de Regulacio Genomica                                                        */
3 /*  and                                                                                     */
4 /*  Cedric Notredame                                                                        */
5 /*  12 Aug 2014 - 22:07.                                                                    */
6 /*All rights reserved.                                                                      */
7 /*This file is part of T-COFFEE.                                                            */
8 /*                                                                                          */
9 /*    T-COFFEE is free software; you can redistribute it and/or modify                      */
10 /*    it under the terms of the GNU General Public License as published by                  */
11 /*    the Free Software Foundation; either version 2 of the License, or                     */
12 /*    (at your option) any later version.                                                   */
13 /*                                                                                          */
14 /*    T-COFFEE is distributed in the hope that it will be useful,                           */
15 /*    but WITHOUT ANY WARRANTY; without even the implied warranty of                        */
16 /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                         */
17 /*    GNU General Public License for more details.                                          */
18 /*                                                                                          */
19 /*    You should have received a copy of the GNU General Public License                     */
20 /*    along with Foobar; if not, write to the Free Software                                 */
21 /*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA             */
22 /*...............................................                                           */
23 /*  If you need some more information                                                       */
24 /*  cedric.notredame@europe.com                                                             */
25 /*...............................................                                           */
26 /******************************COPYRIGHT NOTICE*******************************/
27 // #include "km_util.h"
28 #include "km_coffee_header.h"
29 FILE *
30 my_fopen(char *name_f, char *mode)
31 {
32         FILE *name_F = fopen(name_f, mode);
33         if (name_F == NULL)
34         {
35                 fprintf(stderr, "ERROR: Cannot open file %s!\n", name_f);
36                 exit(1);
37         }
38         else
39                 return name_F;
40 }
41
42
43 void *
44 my_malloc(size_t size)
45 {
46         void *p = malloc(size);
47         if (p == NULL)
48         {
49                 fprintf(stderr, "ERROR: Could not allocate space of size %li\n", size);
50                 exit(1);
51         }
52         return p;
53 }
54
55 void *
56 my_calloc ( size_t num, size_t size )
57 {
58         void *p = calloc(num, size);
59         if (p == NULL)
60         {
61                 fprintf(stderr, "ERROR: Could not allocate space of size %li\n", size*num);
62                 exit(1);
63         }
64         return p;
65 }
66
67
68 void *
69 my_realloc(void *p, size_t size)
70 {
71         p = realloc(p, size);
72         if (p == NULL)
73         {
74                 fprintf(stderr, "ERROR: Could not allocate space of size %li\n", size);
75                 exit(1);
76         }
77         return p;
78 }
79
80
81
82
83 char *
84 my_make_temp_dir(char *templatee, char *function)
85 {
86
87         char *temp_dir_name = (char*)malloc(20 * sizeof(char*));
88         sprintf(temp_dir_name, "%s", templatee);
89 //      char hostname[50];
90 //      gethostname(hostname, 50);
91 //      printf("%s %s\n",hostname, temp_dir_name);
92         if ((temp_dir_name = mkdtemp(temp_dir_name))==NULL)
93         {
94                 int errsv = errno;
95                 fprintf(stderr, "ERROR! A temporary directory could not be created: %s\n",strerror(errsv));
96                 fprintf(stderr, "This error was caused by '%s' in '%s'\n", function);
97
98                 exit(-1);
99         }
100         return temp_dir_name;
101 }
102
103
104
105
106
107
108
109
110