File: porting.cxx

package info (click to toggle)
curves 0.8.7
  • links: PTS
  • area: main
  • in suites: slink
  • size: 704 kB
  • ctags: 1,001
  • sloc: cpp: 6,197; ansic: 519; makefile: 270; sh: 192; fortran: 149
file content (96 lines) | stat: -rw-r--r-- 2,469 bytes parent folder | download | duplicates (2)
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
/* porting.cxx
     $Id: porting.cxx,v 1.3 1998/09/07 00:49:35 elf Exp $

   written by Marc Singer
   19 June 1998

   This file is part of the project CurVeS.  See the file README for
   more information.

   Copyright (C) 1998 Marc Singer

   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
   in a file called COPYING along with this program; if not, write to
   the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
   02139, USA.

   -----------
   DESCRIPTION
   -----------

   Portability and compatibility routines.  Here, we implement
   functions that we expect to find in the standard library. 

*/

#include "std.h"
#include "porting.h"

#if !defined (HAVE_CFMAKERAW)
int cfmakeraw (struct termios *termios_p)
{
  termios_p->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
  termios_p->c_oflag &= ~OPOST;
  termios_p->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
  termios_p->c_cflag &= ~(CSIZE|PARENB);
  termios_p->c_cflag |= CS8;
  return 0;			// Expected return value is not documented
}
#endif


#if !defined (HAVE_VSNPRINTF)

/* vsnprintf

   is a cowardly method for reimplementing the real function.  Since
   curves doesn't really depend on this call this hack is sufficient.
   I'll have to rething this at some point.  *** FIXME

*/  

int vsnprintf (char *sz, size_t cb, const char *szFormat, va_list ap)
{
  size_t result;
#if defined (HAVE_VSPRINTF)
  result = vsprintf (sz, szFormat, ap);
  if (result >= cb) {
    fprintf (stderr, "vsnprintf overrun error\n");
    exit (1);
  }
  return result;
#else
  fprintf (stderr, "vsnprintf or vsnprintf required for to run CurVeS\n");
  exit (1);
#endif
}

#endif 

#if !defined (HAVE_RINDEX)
char* rindex (const char *sz, int c)
{
# if defined (HAVE_STRRCHR)
  return strrchr (sz, c);
#  else
  const char* pch = sz + strlen (sz);
  do {
    if (*pch == c)
      return (char*) pch;
    --pch;
  } while (pch > sz);
  return NULL;
# endif
}

#endif