Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gmsh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Larry Price
gmsh
Commits
139d5b73
Commit
139d5b73
authored
22 years ago
by
Christophe Geuzaine
Browse files
Options
Downloads
Patches
Plain Diff
Replace fwrite with safe_fwrite
parent
ef27886d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
DataStr/List.cpp
+3
-2
3 additions, 2 deletions
DataStr/List.cpp
DataStr/Makefile
+4
-2
4 additions, 2 deletions
DataStr/Makefile
DataStr/SafeIO.cpp
+81
-0
81 additions, 0 deletions
DataStr/SafeIO.cpp
DataStr/SafeIO.h
+28
-0
28 additions, 0 deletions
DataStr/SafeIO.h
with
116 additions
and
4 deletions
DataStr/List.cpp
+
3
−
2
View file @
139d5b73
// $Id: List.cpp,v 1.2
3
2003-0
1-23 20:19:17
geuzaine Exp $
// $Id: List.cpp,v 1.2
4
2003-0
2-10 18:57:02
geuzaine Exp $
//
//
// Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle
// Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle
//
//
...
@@ -27,6 +27,7 @@
...
@@ -27,6 +27,7 @@
#include
"Malloc.h"
#include
"Malloc.h"
#include
"List.h"
#include
"List.h"
#include
"Message.h"
#include
"Message.h"
#include
"SafeIO.h"
static
char
*
startptr
;
static
char
*
startptr
;
...
@@ -450,7 +451,7 @@ void List_WriteToFile(List_T *liste, FILE *file, int format){
...
@@ -450,7 +451,7 @@ void List_WriteToFile(List_T *liste, FILE *file, int format){
Msg
(
GERROR
,
"Bad type of data to write list to file (size = %d)"
,
liste
->
size
);
Msg
(
GERROR
,
"Bad type of data to write list to file (size = %d)"
,
liste
->
size
);
break
;
break
;
case
LIST_FORMAT_BINARY
:
case
LIST_FORMAT_BINARY
:
fwrite
(
liste
->
array
,
liste
->
size
,
n
,
file
);
safe_
fwrite
(
liste
->
array
,
liste
->
size
,
n
,
file
);
break
;
break
;
default
:
default
:
Msg
(
GERROR
,
"Unknown list format"
);
Msg
(
GERROR
,
"Unknown list format"
);
...
...
This diff is collapsed.
Click to expand it.
DataStr/Makefile
+
4
−
2
View file @
139d5b73
# $Id: Makefile,v 1.1
6
200
2
-0
5
-1
8
1
6:31:16
geuzaine Exp $
# $Id: Makefile,v 1.1
7
200
3
-0
2
-1
0
1
8:57:02
geuzaine Exp $
#
#
# Makefile for "libGmshDataStr.a"
# Makefile for "libGmshDataStr.a"
#
#
...
@@ -20,6 +20,7 @@ CFLAGS = $(OPT_FLAGS) $(OS_FLAGS) $(VERSION_FLAGS) $(INCLUDE)
...
@@ -20,6 +20,7 @@ CFLAGS = $(OPT_FLAGS) $(OS_FLAGS) $(VERSION_FLAGS) $(INCLUDE)
SRC
=
List.cpp
\
SRC
=
List.cpp
\
Malloc.cpp
\
Malloc.cpp
\
SafeIO.cpp
\
Tree.cpp
\
Tree.cpp
\
avl.cpp
\
avl.cpp
\
Tools.cpp
Tools.cpp
...
@@ -47,8 +48,9 @@ depend:
...
@@ -47,8 +48,9 @@ depend:
$(
RM
)
Makefile.new
$(
RM
)
Makefile.new
# DO NOT DELETE THIS LINE
# DO NOT DELETE THIS LINE
List.o
:
List.cpp Malloc.h List.h ../Common/Message.h
List.o
:
List.cpp Malloc.h List.h
SafeIO.h
../Common/Message.h
Malloc.o
:
Malloc.cpp Malloc.h ../Common/Message.h
Malloc.o
:
Malloc.cpp Malloc.h ../Common/Message.h
SafeIO.o
:
SafeIO.cpp SafeIO.h ../Common/Message.h
Tree.o
:
Tree.cpp Malloc.h Tree.h avl.h ../Common/Message.h
Tree.o
:
Tree.cpp Malloc.h Tree.h avl.h ../Common/Message.h
avl.o
:
avl.cpp avl.h Malloc.h
avl.o
:
avl.cpp avl.h Malloc.h
Tools.o
:
Tools.cpp Tools.h List.h Tree.h avl.h
Tools.o
:
Tools.cpp Tools.h List.h Tree.h avl.h
This diff is collapsed.
Click to expand it.
DataStr/SafeIO.cpp
0 → 100644
+
81
−
0
View file @
139d5b73
// $Id: SafeIO.cpp,v 1.1 2003-02-10 18:57:02 geuzaine Exp $
//
// Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle
//
// 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.
//
// Please report all bugs and problems to "gmsh@geuz.org".
#include
<stdlib.h>
#include
<string.h>
#include
<errno.h>
#include
<unistd.h>
#include
"SafeIO.h"
#include
"Message.h"
/*
Safe fprintf routine
In a perfect world, one should use this routine. Unfortunately, it
is very, very slow.
We should use a macro, i.e.
#define gprintf(...) { fprintf(__VA_ARGS__); ... }
but but var args don't work with all C preprocessors.
Bottom line: don't use safe_fprintf.
*/
int
safe_fprintf
(
FILE
*
stream
,
char
*
fmt
,
...){
va_list
args
;
va_start
(
args
,
fmt
);
vfprintf
(
stream
,
fmt
,
args
);
va_end
(
args
);
if
(
ferror
(
stream
)){
Msg
(
GERROR
,
strerror
(
errno
));
clearerr
(
stream
);
return
1
;
}
return
0
;
}
/* Safe fwrite routine */
int
safe_fwrite
(
const
void
*
ptr
,
size_t
size
,
size_t
nmemb
,
FILE
*
stream
){
size_t
result
=
fwrite
(
ptr
,
size
,
nmemb
,
stream
);
if
(
result
<
nmemb
){
if
(
result
>=
0
)
/* Partial write */
Msg
(
GERROR
,
"Disk full"
);
else
Msg
(
GERROR
,
strerror
(
errno
));
Msg
(
GERROR
,
"Truncating output file"
);
if
(
fflush
(
stream
)
<
0
)
Msg
(
GERROR
,
"EOF reached"
);
if
(
ftruncate
(
fileno
(
stream
),
0
)
<
0
)
Msg
(
GERROR
,
strerror
(
errno
));
if
(
fclose
(
stream
)
<
0
)
Msg
(
GERROR
,
strerror
(
errno
));
return
1
;
}
return
0
;
}
This diff is collapsed.
Click to expand it.
DataStr/SafeIO.h
0 → 100644
+
28
−
0
View file @
139d5b73
#ifndef _SAFE_IO_H_
// Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle
//
// 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.
//
// Please report all bugs and problems to "gmsh@geuz.org".
#include
<stdarg.h>
#include
<stdio.h>
int
safe_fprintf
(
FILE
*
stream
,
char
*
fmt
,
...);
int
safe_fwrite
(
const
void
*
ptr
,
size_t
size
,
size_t
nmemb
,
FILE
*
stream
);
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment