File: support.c

package info (click to toggle)
medussa 0.8-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,004 kB
  • ctags: 1,156
  • sloc: ansic: 9,049; sh: 3,319; makefile: 113
file content (123 lines) | stat: -rw-r--r-- 2,559 bytes parent folder | download | duplicates (3)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
 * medussa - a distributed cracking system
 * Copyright (C) 1999 Kostas Evangelinos <kos@bastard.net>
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * 
 */

/*
 * $Id: support.c,v 1.2 2000/11/14 04:03:29 kos Exp $
 *
 */

#include "config.h"

#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdarg.h>
#include <time.h>

#include "support.h"


#ifndef HAVE_GETCWD
char *
getcwd(char *buf, size_t size) {
  if(size<2)
    return NULL;
  buf[0] = '/';
  buf[1] = '\0';
  return buf;
}
#endif

#ifndef HAVE_GETHOSTNAME
int
gethostname(char *name, size_t len) {
  strncpy(name, "node", len);
  return 0;
}
#endif

#ifndef HAVE_STRDUP
char *
strdup(const char *s) {
  char *r;
  if(!(r = (char *)malloc(strlen(s))))
    return NULL;
  return r;
}
#endif

#ifndef HAVE_STRERROR
char *
strerror(int errnum) {
  if(errnum>sys_nerr)
    return "No such error";
  return sys_errlist[errnum];
}
#endif

#ifndef HAVE_SNPRINTF
#warning "You dont have snprintf(). The resulting executable is not secure and should not be used"
#define snprintf sprintf
#endif

#ifndef HAVE_GMTIME_R
struct tm *
gmtime_r(const time_t *timep, struct tm *tp) {
  struct tm *t;

  if(!(t = gmtime(timep)))
    return (struct tm *)NULL;
  memcpy((void *)tp, (void *)t, sizeof(struct tm));
  return tp;
}
#endif

#ifndef HAVE_LOCALTIME_R
struct tm *
localtime_r(const time_t *timep, struct tm *tp) {
  struct tm *t;

  if(!(t = localtime(timep)))
    return (struct tm *)NULL;
  memcpy((void *)tp, (void *)t, sizeof(struct tm));
  return tp;
}
#endif

#ifndef HAVE_VSYSLOG
#include <stdarg.h>
#ifdef HAVE_SYSLOG
#include <syslog.h>
#endif
#include "common.h"

void
vsyslog(int pri, const char *fmt, ...) {
  va_list vl;
  uchar fmtstr[DEF_LINELEN];

  va_start(vl, fmt);
  vsnprintf(fmtstr, DEF_LINELEN, fmt, vl);
  va_end(vl);
  syslog(pri, fmtstr, strlen(fmtstr));  
}
#endif