Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpim-sw
libcdi
Commits
283fcb0c
Commit
283fcb0c
authored
Mar 12, 2009
by
Uwe Schulzweida
Browse files
replaced strncpy/strncmp by memcpy/memcmp
parent
1cc2e835
Changes
13
Expand all
Hide whitespace changes
Inline
Side-by-side
ChangeLog
View file @
283fcb0c
...
...
@@ -8,6 +8,7 @@
* gridInqXinc: bug fix
* grid_check_cyclic: support for curvilinear grids without bounds
* streamOpenAppen: set ncmode to 2 (bug fix)
* replaced strncpy/strncmp by memcpy/memcmp
* Version 1.3.1 released
2009-01-15 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
...
...
src/cdf_int.c
View file @
283fcb0c
...
...
@@ -42,7 +42,7 @@ void cdf_create(const char *path, int cmode, int *ncidp)
strcpy(basename, "./");
else
{
strn
cpy(basename, path, pend-path);
mem
cpy(basename, path, pend-path);
basename[pend-path] = 0;
}
...
...
@@ -85,7 +85,7 @@ int cdf_open(const char *path, int omode, int *ncidp)
size_t
chunksizehint
=
0
;
#if defined (HAVE_LIBNC_DAP)
if
(
strn
cmp
(
path
,
"http:"
,
5
)
==
0
)
dapfile
=
TRUE
;
if
(
mem
cmp
(
path
,
"http:"
,
5
)
==
0
)
dapfile
=
TRUE
;
#endif
if
(
dapfile
)
...
...
src/dmemory.c
View file @
283fcb0c
...
...
@@ -320,7 +320,7 @@ static int memListNewEntry(int mtype, void *ptr, size_t size, size_t nobj,
len
=
strlen
(
file
);
if
(
len
>
MAXNAME
-
1
)
len
=
MAXNAME
-
1
;
(
void
)
strn
cpy
(
memTable
[
memID
].
file
,
file
,
len
);
(
void
)
mem
cpy
(
memTable
[
memID
].
file
,
file
,
len
);
memTable
[
memID
].
file
[
len
]
=
'\0'
;
}
else
...
...
@@ -333,7 +333,7 @@ static int memListNewEntry(int mtype, void *ptr, size_t size, size_t nobj,
len
=
strlen
(
caller
);
if
(
len
>
MAXNAME
-
1
)
len
=
MAXNAME
-
1
;
(
void
)
strn
cpy
(
memTable
[
memID
].
caller
,
caller
,
len
);
(
void
)
mem
cpy
(
memTable
[
memID
].
caller
,
caller
,
len
);
memTable
[
memID
].
caller
[
len
]
=
'\0'
;
}
else
...
...
@@ -388,7 +388,7 @@ static int memListChangeEntry(void *ptrold, void *ptr, size_t size,
len
=
strlen
(
file
);
if
(
len
>
MAXNAME
-
1
)
len
=
MAXNAME
-
1
;
(
void
)
strn
cpy
(
memTable
[
memID
].
file
,
file
,
len
);
(
void
)
mem
cpy
(
memTable
[
memID
].
file
,
file
,
len
);
memTable
[
memID
].
file
[
len
]
=
'\0'
;
}
else
...
...
@@ -401,7 +401,7 @@ static int memListChangeEntry(void *ptrold, void *ptr, size_t size,
len
=
strlen
(
caller
);
if
(
len
>
MAXNAME
-
1
)
len
=
MAXNAME
-
1
;
(
void
)
strn
cpy
(
memTable
[
memID
].
caller
,
caller
,
len
);
(
void
)
mem
cpy
(
memTable
[
memID
].
caller
,
caller
,
len
);
memTable
[
memID
].
caller
[
len
]
=
'\0'
;
}
else
...
...
src/griblib.c
View file @
283fcb0c
/* Automatically generated by m214003 at 2009-03-1
1
, do not edit */
/* Automatically generated by m214003 at 2009-03-1
2
, do not edit */
/* GRIBLIB_VERSION="1.3.0" */
...
...
@@ -5028,7 +5028,7 @@ int gribCheckFiletype(int fileID)
if
(
fileRead
(
fileID
,
buffer
,
4
)
!=
4
)
return
(
found
);
if
(
strn
cmp
(
buffer
,
"GRIB"
,
4
)
==
0
)
if
(
mem
cmp
(
buffer
,
"GRIB"
,
4
)
==
0
)
{
found
=
1
;
if
(
GRB_Debug
)
Message
(
func
,
"found GRIB file = %s"
,
fileInqName
(
fileID
));
...
...
@@ -8380,7 +8380,7 @@ int gribUnzip(unsigned char *dbuf, long dbufsize, unsigned char *sbuf, long sbu
return
(
gribLen
);
}
static
const
char
grb_libvers
[]
=
"1.3.0"
" of ""Mar 1
1
2009"" ""12:0
4:04
"
;
static
const
char
grb_libvers
[]
=
"1.3.0"
" of ""Mar 1
2
2009"" ""12:0
7:20
"
;
const
char
*
gribLibraryVersion
(
void
)
{
...
...
src/institution.c
View file @
283fcb0c
...
...
@@ -137,7 +137,7 @@ int institutInq(int center, int subcenter, const char *name, const char *longnam
if
(
instituts
[
instID
].
name
)
{
len
=
strlen
(
instituts
[
instID
].
name
);
if
(
strn
cmp
(
instituts
[
instID
].
name
,
name
,
len
)
==
0
)
break
;
if
(
mem
cmp
(
instituts
[
instID
].
name
,
name
,
len
)
==
0
)
break
;
}
}
}
...
...
@@ -146,7 +146,7 @@ int institutInq(int center, int subcenter, const char *name, const char *longnam
if
(
instituts
[
instID
].
longname
)
{
len
=
strlen
(
instituts
[
instID
].
longname
);
if
(
strn
cmp
(
instituts
[
instID
].
longname
,
longname
,
len
)
==
0
)
break
;
if
(
mem
cmp
(
instituts
[
instID
].
longname
,
longname
,
len
)
==
0
)
break
;
}
}
else
...
...
src/make_fint.c
View file @
283fcb0c
...
...
@@ -148,11 +148,11 @@ void fortran_interface(char *fname, char *fnameinc, char *fnameint)
linelen
-=
1
;
functype
=
ISVOID
;
funcargc
=
0
;
if
(
strn
cmp
(
line
,
"int"
,
3
)
==
0
||
strn
cmp
(
line
,
"void"
,
4
)
==
0
||
strn
cmp
(
line
,
"char"
,
4
)
==
0
||
strn
cmp
(
line
,
"const"
,
5
)
==
0
||
strn
cmp
(
line
,
"double"
,
6
)
==
0
)
if
(
mem
cmp
(
line
,
"int"
,
3
)
==
0
||
mem
cmp
(
line
,
"void"
,
4
)
==
0
||
mem
cmp
(
line
,
"char"
,
4
)
==
0
||
mem
cmp
(
line
,
"const"
,
5
)
==
0
||
mem
cmp
(
line
,
"double"
,
6
)
==
0
)
{
/* printf("%s\n", line); */
ii
=
0
;
...
...
@@ -165,32 +165,32 @@ void fortran_interface(char *fname, char *fnameinc, char *fnameint)
line
[
ii
]
=
0
;
/* printf("%s\n", line); */
pline
=
line
;
if
(
strn
cmp
(
line
,
"int"
,
3
)
==
0
)
if
(
mem
cmp
(
line
,
"int"
,
3
)
==
0
)
{
functype
=
ISINT
;
pline
+=
3
;
}
else
if
(
strn
cmp
(
line
,
"void"
,
4
)
==
0
)
else
if
(
mem
cmp
(
line
,
"void"
,
4
)
==
0
)
{
functype
=
ISVOID
;
pline
+=
4
;
}
else
if
(
strn
cmp
(
line
,
"double*"
,
7
)
==
0
)
else
if
(
mem
cmp
(
line
,
"double*"
,
7
)
==
0
)
{
printf
(
"skip: line %3d double *
\n
"
,
lineno
);
continue
;
}
else
if
(
strn
cmp
(
line
,
"double"
,
6
)
==
0
)
else
if
(
mem
cmp
(
line
,
"double"
,
6
)
==
0
)
{
functype
=
ISDOUBLE
;
pline
+=
6
;
}
else
if
(
strn
cmp
(
line
,
"char*"
,
5
)
==
0
)
else
if
(
mem
cmp
(
line
,
"char*"
,
5
)
==
0
)
{
functype
=
ISCONSTSTRING
;
pline
+=
5
;
}
else
if
(
strn
cmp
(
line
,
"constchar*"
,
10
)
==
0
)
else
if
(
mem
cmp
(
line
,
"constchar*"
,
10
)
==
0
)
{
functype
=
ISCONSTSTRING
;
pline
+=
10
;
...
...
@@ -203,7 +203,7 @@ void fortran_interface(char *fname, char *fnameinc, char *fnameint)
len
=
0
;
while
(
isalnum
((
int
)
pline
[
len
])
)
len
++
;
strn
cpy
(
funcname
,
pline
,
len
);
mem
cpy
(
funcname
,
pline
,
len
);
funcname
[
len
]
=
0
;
/* printf("%s\n", funcname);*/
pline
+=
len
;
...
...
@@ -237,46 +237,46 @@ void fortran_interface(char *fname, char *fnameinc, char *fnameint)
for
(
i
=
0
;
i
<
funcargc
;
i
++
)
{
pline
=
funcargname
[
i
];
if
(
strn
cmp
(
pline
,
"const"
,
5
)
==
0
&&
strn
cmp
(
pline
,
"constchar*"
,
10
)
!=
0
)
pline
+=
5
;
if
(
mem
cmp
(
pline
,
"const"
,
5
)
==
0
&&
mem
cmp
(
pline
,
"constchar*"
,
10
)
!=
0
)
pline
+=
5
;
if
(
strn
cmp
(
pline
,
"void"
,
4
)
==
0
)
if
(
mem
cmp
(
pline
,
"void"
,
4
)
==
0
)
{
pline
+=
4
;
funcargtype
[
i
]
=
ISVOID
;
funcargname
[
i
]
=
pline
;
}
else
if
(
strn
cmp
(
pline
,
"constchar*"
,
10
)
==
0
)
else
if
(
mem
cmp
(
pline
,
"constchar*"
,
10
)
==
0
)
{
pline
+=
10
;
funcargtype
[
i
]
=
ISSTRING
;
funcargname
[
i
]
=
pline
;
}
else
if
(
strn
cmp
(
pline
,
"char*"
,
5
)
==
0
)
else
if
(
mem
cmp
(
pline
,
"char*"
,
5
)
==
0
)
{
pline
+=
5
;
funcargtype
[
i
]
=
ISSTRINGP
;
funcargname
[
i
]
=
pline
;
}
else
if
(
strn
cmp
(
pline
,
"int*"
,
4
)
==
0
)
else
if
(
mem
cmp
(
pline
,
"int*"
,
4
)
==
0
)
{
pline
+=
4
;
funcargtype
[
i
]
=
ISINTP
;
funcargname
[
i
]
=
pline
;
}
else
if
(
strn
cmp
(
pline
,
"int"
,
3
)
==
0
)
else
if
(
mem
cmp
(
pline
,
"int"
,
3
)
==
0
)
{
pline
+=
3
;
funcargtype
[
i
]
=
ISINT
;
funcargname
[
i
]
=
pline
;
}
else
if
(
strn
cmp
(
pline
,
"double*"
,
7
)
==
0
)
else
if
(
mem
cmp
(
pline
,
"double*"
,
7
)
==
0
)
{
pline
+=
7
;
funcargtype
[
i
]
=
ISDOUBLEP
;
funcargname
[
i
]
=
pline
;
}
else
if
(
strn
cmp
(
pline
,
"double"
,
6
)
==
0
)
else
if
(
mem
cmp
(
pline
,
"double"
,
6
)
==
0
)
{
pline
+=
6
;
funcargtype
[
i
]
=
ISDOUBLE
;
...
...
@@ -419,7 +419,7 @@ void fortran_interface(char *fname, char *fnameinc, char *fnameint)
nfdoc
++
;
}
}
else
if
(
strn
cmp
(
line
,
"#define"
,
7
)
==
0
)
else
if
(
mem
cmp
(
line
,
"#define"
,
7
)
==
0
)
{
pline
=
line
;
pline
+=
7
;
...
...
@@ -442,7 +442,7 @@ void fortran_interface(char *fname, char *fnameinc, char *fnameint)
fprintf
(
fpinc
,
" INTEGER %-22s
\n
"
,
parname
);
fprintf
(
fpinc
,
" PARAMETER (%-22s = %2d)
\n
"
,
parname
,
parvalue
);
}
else
if
(
strn
cmp
(
line
,
"/*"
,
2
)
==
0
)
else
if
(
mem
cmp
(
line
,
"/*"
,
2
)
==
0
)
{
int
dpos
=
0
;
pline
=
line
;
...
...
@@ -573,8 +573,8 @@ int main(int argc, char *argv[])
if
(
cp
==
NULL
)
len
=
strlen
(
fname
);
else
len
=
cp
-
fname
;
strn
cpy
(
fnameinc
,
fname
,
len
);
strn
cpy
(
fnameint
,
fname
,
len
);
mem
cpy
(
fnameinc
,
fname
,
len
);
mem
cpy
(
fnameint
,
fname
,
len
);
strcpy
(
fnameinc
+
len
,
".inc"
);
strcpy
(
fnameint
+
len
,
"Fortran.c"
);
...
...
src/model.c
View file @
283fcb0c
...
...
@@ -311,9 +311,9 @@ int modelInq(int instID, int modelgribID, char *name)
if
(
modelptr
->
name
)
{
len
=
strlen
(
modelptr
->
name
);
if
(
strn
cmp
(
modelptr
->
name
,
name
,
len
)
==
0
)
break
;
if
(
mem
cmp
(
modelptr
->
name
,
name
,
len
)
==
0
)
break
;
len
=
strlen
(
name
);
if
(
strn
cmp
(
modelptr
->
name
,
name
,
len
)
==
0
)
break
;
if
(
mem
cmp
(
modelptr
->
name
,
name
,
len
)
==
0
)
break
;
}
}
}
...
...
src/stream.c
View file @
283fcb0c
...
...
@@ -112,7 +112,7 @@ static int getFiletype(const char *filename, int *byteorder)
if
(
fileID
==
CDI_UNDEFID
)
{
if
(
strn
cmp
(
filename
,
"http:"
,
5
)
==
0
)
if
(
mem
cmp
(
filename
,
"http:"
,
5
)
==
0
)
return
(
FILETYPE_NC
);
else
return
(
CDI_ESYSTEM
);
...
...
@@ -122,7 +122,7 @@ static int getFiletype(const char *filename, int *byteorder)
fileRewind
(
fileID
);
if
(
strn
cmp
(
buffer
,
"GRIB"
,
4
)
==
0
)
if
(
mem
cmp
(
buffer
,
"GRIB"
,
4
)
==
0
)
{
version
=
buffer
[
7
];
if
(
version
<=
1
)
...
...
@@ -131,17 +131,17 @@ static int getFiletype(const char *filename, int *byteorder)
if
(
CDI_Debug
)
Message
(
func
,
"found GRIB file = %s, version %d"
,
filename
,
version
);
}
}
else
if
(
strn
cmp
(
buffer
,
"CDF
\001
"
,
4
)
==
0
)
else
if
(
mem
cmp
(
buffer
,
"CDF
\001
"
,
4
)
==
0
)
{
filetype
=
FILETYPE_NC
;
if
(
CDI_Debug
)
Message
(
func
,
"found CDF1 file = %s"
,
filename
);
}
else
if
(
strn
cmp
(
buffer
,
"CDF
\002
"
,
4
)
==
0
)
else
if
(
mem
cmp
(
buffer
,
"CDF
\002
"
,
4
)
==
0
)
{
filetype
=
FILETYPE_NC2
;
if
(
CDI_Debug
)
Message
(
func
,
"found CDF2 file = %s"
,
filename
);
}
else
if
(
strn
cmp
(
buffer
+
1
,
"HDF"
,
3
)
==
0
)
else
if
(
mem
cmp
(
buffer
+
1
,
"HDF"
,
3
)
==
0
)
{
filetype
=
FILETYPE_NC4
;
if
(
CDI_Debug
)
Message
(
func
,
"found HDF file = %s"
,
filename
);
...
...
@@ -225,8 +225,8 @@ int get_fnames(const char *argument, char *fnames[], int max_fnames)
{
pch
=
&
argument
[
i
+
1
];
len
-=
(
i
+
1
);
if
(
len
&&
(
strn
cmp
(
argument
,
"filelist:"
,
i
)
==
0
||
strn
cmp
(
argument
,
"flist:"
,
i
)
==
0
)
)
if
(
len
&&
(
mem
cmp
(
argument
,
"filelist:"
,
i
)
==
0
||
mem
cmp
(
argument
,
"flist:"
,
i
)
==
0
)
)
{
for
(
i
=
0
;
i
<
len
;
++
i
)
if
(
pch
[
i
]
==
','
)
nfiles
++
;
...
...
@@ -282,7 +282,7 @@ int get_fnames(const char *argument, char *fnames[], int max_fnames)
}
}
}
else
if
(
len
&&
strn
cmp
(
argument
,
"ls:"
,
i
)
==
0
)
else
if
(
len
&&
mem
cmp
(
argument
,
"ls:"
,
i
)
==
0
)
{
char
command
[
4096
];
FILE
*
pfp
;
...
...
src/stream_cdf.c
View file @
283fcb0c
This diff is collapsed.
Click to expand it.
src/stream_grb.c
View file @
283fcb0c
...
...
@@ -4,7 +4,7 @@
#include <stdio.h>
#include <string.h>
#include <math.h>
/* modf */
#include <math.h>
/* modf */
#include <float.h>
/* FLT_EPSILON */
#include <sys/types.h>
...
...
@@ -2101,7 +2101,7 @@ void grbDefLevel(int *isec1, int *isec2, double *fsec2, int zaxisID, int levelID
Warning
(
func
,
"pressure level of %f Pa is below 0."
,
level
);
zaxisInqUnits
(
zaxisID
,
units
);
if
(
strn
cmp
(
units
,
"hPa"
,
3
)
==
0
||
strn
cmp
(
units
,
"mb"
,
2
)
==
0
)
if
(
mem
cmp
(
units
,
"hPa"
,
3
)
==
0
||
mem
cmp
(
units
,
"mb"
,
2
)
==
0
)
level
=
level
*
100
;
ilevel
=
(
int
)
level
;
...
...
src/stream_ieg.c
View file @
283fcb0c
...
...
@@ -380,7 +380,7 @@ void iegDefLevel(int *pdb, int *gdb, double *vct, int zaxisID, int levelID)
Warning
(
func
,
"pressure level of %f Pa is below 0."
,
level
);
zaxisInqUnits
(
zaxisID
,
units
);
if
(
strn
cmp
(
units
,
"hPa"
,
3
)
==
0
||
strn
cmp
(
units
,
"mb"
,
2
)
==
0
)
if
(
mem
cmp
(
units
,
"hPa"
,
3
)
==
0
||
mem
cmp
(
units
,
"mb"
,
2
)
==
0
)
level
=
level
*
100
;
ilevel
=
(
int
)
level
;
...
...
src/table.c
View file @
283fcb0c
...
...
@@ -158,7 +158,7 @@ int decodeForm1(char *pline, char *name, char *longname, char *units)
len
=
pline
-
pstart
;
if
(
len
>
0
)
{
strn
cpy
(
name
,
pstart
,
len
);
mem
cpy
(
name
,
pstart
,
len
);
name
[
len
]
=
0
;
}
else
...
...
@@ -185,7 +185,7 @@ int decodeForm1(char *pline, char *name, char *longname, char *units)
len
=
pend
-
pstart
+
1
;
if
(
len
>
0
)
{
strn
cpy
(
longname
,
pstart
,
len
);
mem
cpy
(
longname
,
pstart
,
len
);
longname
[
len
]
=
0
;
}
pstart
=
strrchr
(
pline
,
'['
);
...
...
@@ -200,7 +200,7 @@ int decodeForm1(char *pline, char *name, char *longname, char *units)
len
=
pend
-
pstart
+
1
;
if
(
len
>
0
)
{
strn
cpy
(
units
,
pstart
,
len
);
mem
cpy
(
units
,
pstart
,
len
);
units
[
len
]
=
0
;
}
}
...
...
@@ -227,7 +227,7 @@ int decodeForm2(char *pline, char *name, char *longname, char *units)
len
=
pend
-
pline
;
if
(
len
>
0
)
{
strn
cpy
(
name
,
pline
,
len
);
mem
cpy
(
name
,
pline
,
len
);
name
[
len
]
=
0
;
}
return
(
0
);
...
...
@@ -239,7 +239,7 @@ int decodeForm2(char *pline, char *name, char *longname, char *units)
len
=
pend
-
pline
+
1
;
if
(
len
>
0
)
{
strn
cpy
(
name
,
pline
,
len
);
mem
cpy
(
name
,
pline
,
len
);
name
[
len
]
=
0
;
}
}
...
...
@@ -254,7 +254,7 @@ int decodeForm2(char *pline, char *name, char *longname, char *units)
len
=
pend
-
pline
+
1
;
if
(
len
>
0
)
{
strn
cpy
(
longname
,
pline
,
len
);
mem
cpy
(
longname
,
pline
,
len
);
longname
[
len
]
=
0
;
}
...
...
@@ -269,7 +269,7 @@ int decodeForm2(char *pline, char *name, char *longname, char *units)
while
(
isspace
((
int
)
*
pend
)
)
pend
--
;
len
=
pend
-
pline
+
1
;
if
(
len
<
0
)
len
=
0
;
strn
cpy
(
units
,
pline
,
len
);
mem
cpy
(
units
,
pline
,
len
);
units
[
len
]
=
0
;
}
...
...
@@ -429,7 +429,7 @@ int tableInq(int modelID, int tablenum, const char *tablename)
{
/* len = strlen(parTable[tableID].name); */
len
=
strlen
(
tablename
);
if
(
strn
cmp
(
parTable
[
tableID
].
name
,
tablename
,
len
)
==
0
)
break
;
if
(
mem
cmp
(
parTable
[
tableID
].
name
,
tablename
,
len
)
==
0
)
break
;
}
}
if
(
tableID
==
MAX_TABLE
)
tableID
=
UNDEFID
;
...
...
src/vlist_att.c
View file @
283fcb0c
...
...
@@ -46,7 +46,7 @@ CDI_att *find_att(CDI_atts *attsp, const char *name)
{
attp
=
&
(
attsp
->
value
[
attid
]);
if
(
attp
->
namesz
==
slen
)
if
(
strn
cmp
(
attp
->
name
,
name
,
slen
)
==
0
)
if
(
mem
cmp
(
attp
->
name
,
name
,
slen
)
==
0
)
{
return
(
attp
);
/* Normal return */
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment