summaryrefslogtreecommitdiff
path: root/srec/include/portable.h
blob: 3d39931b191e4d5bff75c345030d80ef309b7cb5 (plain)
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
/*---------------------------------------------------------------------------*
 *  portable.h  *
 *                                                                           *
 *  Copyright 2007, 2008 Nuance Communciations, Inc.                               *
 *                                                                           *
 *  Licensed under the Apache License, Version 2.0 (the 'License');          *
 *  you may not use this file except in compliance with the License.         *
 *                                                                           *
 *  You may obtain a copy of the License at                                  *
 *      http://www.apache.org/licenses/LICENSE-2.0                           *
 *                                                                           *
 *  Unless required by applicable law or agreed to in writing, software      *
 *  distributed under the License is distributed on an 'AS IS' BASIS,        *
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 
 *  See the License for the specific language governing permissions and      *
 *  limitations under the License.                                           *
 *                                                                           *
 *---------------------------------------------------------------------------*/


#ifndef _h_portable_
#define _h_portable_

#ifdef SET_RCSID
static const char portable_h[] = "$Id: portable.h,v 1.4.10.4 2007/10/15 18:06:25 dahan Exp $";
#endif


#include <math.h>

#include "passert.h"
#include "pmemory.h"
#include "PFileSystem.h"
#include "plog.h"
#include "pstdio.h"
#include "ptypes.h"
#include "setting.h"

#define ASSERT passert

/* QNX defines log in math.h */
#ifndef log
#define log(X)          ((X) <= 1e-32 ? -MAX_LOG : log(X))
/* #define exp(X)          ((X) < FLT_MIN_EXP ? 0.0 : exp(X)) */
#endif
/*  Allocation macros
*/

#if defined(__sgi)
#define inline
#elif defined(unix)
#define inline __inline__
#endif

  static PINLINE PFile* file_must_open(PFile* afile, const LCHAR *name, const LCHAR *mode, ESR_BOOL littleEndian)
  {
    PFile* fp;
    ESR_ReturnCode rc;
    
    fp = pfopen ( name, mode );

    if (fp == NULL)
    {
      LCHAR path[P_PATH_MAX];
      LCHAR *tmp = path;
      size_t len;
      
      len = P_PATH_MAX;
      CHKLOG(rc, pf_get_cwd (path, &len));
      PLogError(L("Could not open file %s, mode=%s, cwd=%s\n"), name, mode, tmp);
      /* passert(0); */
      fp = NULL;
    }
    return fp;
CLEANUP:
    return NULL;
  }

#define report_malloc_usage() do { } while(0); /* do nothing */
#define log_report PLogMessage

#define SERVICE_ERROR(X) do \
  { \
    log_report("service error (%d)\n", X); \
    assert(0); \
    exit(1); \
  } while(0)


#endif