File: ncpoco.c

package info (click to toggle)
netcdf 1%3A4.9.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 115,904 kB
  • sloc: ansic: 278,886; sh: 14,183; cpp: 5,971; yacc: 2,612; makefile: 1,999; lex: 1,218; javascript: 280; xml: 173; awk: 2
file content (126 lines) | stat: -rw-r--r-- 2,982 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
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
124
125
126
/*********************************************************************
 *   Copyright 1993, UCAR/Unidata
 *   See netcdf/COPYRIGHT file for copying and redistribution conditions.
 *   Derived from poco library from Boost Software: see nccpoco/SourceLicense file.
 *********************************************************************/

#include "config.h"
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#include "netcdf.h"
#include "ncpoco.h"

/**************************************************/
#ifdef _WIN32
extern struct NCPAPI ncp_win32_api;
#else
extern struct NCPAPI ncp_unix_api;
#endif

/**************************************************/

/* Creates a SharedLib object. */
EXTERNL int
ncpsharedlibnew(NCPSharedLib** libp)
{
    int ret = NC_NOERR;
    NCPSharedLib* lib;
    lib = (NCPSharedLib*)calloc(1,sizeof(NCPSharedLib));
    if(lib == 0)
	{ret = NC_ENOMEM; goto done;}
    /* fill in the api */
#ifdef _WIN32
    lib->api = ncp_win32_api;
#else
    lib->api = ncp_unix_api;
#endif
    ret = lib->api.init(lib);
    if(ret == NC_NOERR && libp)
	*libp = lib;
	
done:
    return ret;
}

/* free this shared library */
EXTERNL int
ncpsharedlibfree(NCPSharedLib* lib)
{
    int ret = NC_NOERR;
    if(lib == NULL) return NC_NOERR;
    ret = lib->api.unload(lib);
    ret = lib->api.reclaim(lib);
    /* reclaim common stuff */
    nullfree(lib->path);
    free(lib);
    return ret;
}

/*
Loads a shared library from the given path using specified flags.
Returns error if a library has already been loaded or cannot be loaded.
*/
EXTERNL int
ncpload(NCPSharedLib* lib, const char* path, int flags)
{
    if(lib == NULL || path == NULL) return NC_EINVAL;
    ncpclearerrmsg(lib);
    return lib->api.load(lib,path,flags);
}

EXTERNL int
ncpunload(NCPSharedLib* lib) /* Unloads a shared library. */
{
    if(lib == NULL) return NC_EINVAL;
    ncpclearerrmsg(lib);
    return lib->api.unload(lib);
}

EXTERNL int
ncpisloaded(NCPSharedLib* lib) /* Returns 1 iff a library has been loaded. */
{
    if(lib == NULL) return 0;
    return lib->api.isloaded(lib);
}

/* Returns the address of the symbol with the given name.
   For functions, this is the entry point of the function.
   Return error if the symbol does not exist
*/
EXTERNL void*
ncpgetsymbol(NCPSharedLib* lib,const char* name)
{
    if(lib == NULL) return NULL;
    ncpclearerrmsg(lib);
    return lib->api.getsymbol(lib,name);
}

/* Returns the path of the library, as specified in
   a call to load()
*/
EXTERNL const char*
ncpgetpath(NCPSharedLib* lib)
{
    if(lib == NULL) return NULL;
    return lib->api.getpath(lib);
}

/* Returns the last err msg. */
EXTERNL const char*
ncpgeterrmsg(NCPSharedLib* lib)
{
    if(lib == NULL) return NULL;
    return (lib->err.msg[0] == '\0' ? NULL : lib->err.msg);
}

/* Clear the last err msg. */
EXTERNL void
ncpclearerrmsg(NCPSharedLib* lib)
{
    if(lib == NULL) return;
    memset(lib->err.msg,0,sizeof(lib->err.msg));
}