Mail Archives: djgpp/1998/02/09/10:31:03
Dit is een meerdelig bericht in MIME-indeling.
------=_NextPart_000_0004_01BD3578.39E50560
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
I've made a class to work with files. I first made it with fstream, but =
i got a problem with binary opening of the files. Now, i've don it with =
simple open and close...
Whats the problem is that everything is working normally, but when I =
call file.close(); (a instance of ifctypt), the program calls SIGABRT =
and aborts. It doesn't really goes to the routines, but then it calls =
the routine, it goes to the last line in the library of the project and =
quits (with a sigabrt). I'm getting really sick of this so please help =
me.
The library in wich the class is made is this (partially!!!)
struct ifcrypt
{
public:
ifcrypt( char * filename, const char * _pasword );
ifcrypt( void );
~ifcrypt( void );
void open( char * filename, const char * _pasword );
void readline( char * line, int len, char endchar=3D'\n' );
void readlen( char * line, int len );
void close( void );
bool correct( void )
{ return !file<0; };
private:
char decryptchar( char * chars );
char * pasword;
bool fileopen;
int file;
};
ifcrypt::~ifcrypt( void )
{
// This one is emty. Forfuture changes, it is defined anyway.
}
char ifcrypt::decryptchar( char * chars )
{
// Sorry, couldn't give this. CLASSIFIED
}
ifcrypt::ifcrypt( void )
{
fileopen=3Dfalse;
}
ifcrypt::ifcrypt( char * filename, const char * _pasword )
{
open( filename, _pasword );
}
void ifcrypt::open( char * filename, const char * _pasword )
{
char * dummy =3D (char *)malloc( strlen( CRYPT_STRING )+1 ); // =
Crypt_string is a identifier string with #define.
file =3D ::open( filename, O_BINARY ); // open is included from the =
library
pasword =3D (char *)malloc( strlen( _pasword )+1 );
strcpy( pasword, _pasword );
readline( dummy, strlen( CRYPT_STRING ));
if( strcmp( dummy, CRYPT_STRING )=3D=3D0 )
fileopen=3Dtrue;
else
{
fileopen=3Dfalse;
::close( file );
}
free( dummy );
return;
}
void ifcrypt::close( void )
{
::close( file );
free( pasword );
}
void ifcrypt::readline( char * line, int len, char endchar )
{
char chars[2];
char returned;
int i;
for( i=3D0; i<len; i++ )
{
read( file, chars, 2 );
line[i] =3D decryptchar( chars );
if( line[i]=3D=3Dendchar )
{
line[i+1]=3D0;
break;
}
}
line[len]=3D0;
}
void ifcrypt::readlen( char * line, int len )
{
char chars[2];
char returned;
int i;
for( i=3D0; i<len; i++ )
{
read( file, chars, 2 );
line[i] =3D decryptchar( chars );
}
}
Thanks,
Pieter van Ginkel,
the Netherlands.
pginkel AT westbrabant DOT net
http://home.westbrabant.net/~pginkel (ie40 or higher only!!!)
------=_NextPart_000_0004_01BD3578.39E50560
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>
<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type>
<META content=3D'"MSHTML 4.71.1712.3"' name=3DGENERATOR>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT color=3D#000000 face=3DArial><FONT size=3D3>I've made a class =
to work with=20
files. I first made it with fstream, but i got a problem with binary =
opening of=20
the files. Now, i've don it with simple open and =
close...</FONT></FONT><FONT=20
size=3D3></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT size=3D3>Whats the problem =
is that=20
everything is working normally, but when I call file.close(); (a =
instance of=20
ifctypt), the program calls SIGABRT and aborts. It doesn't really goes =
to the=20
routines, but then it calls the routine, it goes to the last line in the =
library=20
of the project and quits (with a sigabrt). I'm getting really sick of =
this so=20
please help me.</FONT></FONT><FONT size=3D3></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT size=3D3>The library in =
wich the class=20
is made is this (partially!!!)</FONT></FONT><FONT =
size=3D3></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT =
size=3D3></FONT></FONT><FONT=20
size=3D3></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT size=3D3>struct=20
ifcrypt<BR>{<BR>public:<BR> ifcrypt( char * filename, const char * =
_pasword );<BR> ifcrypt( void );<BR> ~ifcrypt( void =
);<BR> =20
void open( char * filename, const char * _pasword );<BR> void =
readline(=20
char * line, int len, char endchar=3D'\n' );<BR> void readlen( =
char * line,=20
int len );<BR> void close( void );</FONT></FONT><FONT=20
size=3D3></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT size=3D3> bool =
correct( void=20
)<BR> { return !file<0; };</FONT></FONT><FONT=20
size=3D3></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT =
size=3D3>private:<BR> char=20
decryptchar( char * chars );</FONT></FONT><FONT =
size=3D3></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT size=3D3> char *=20
pasword;<BR> bool fileopen;<BR> int =
file;<BR>};</FONT></FONT><FONT=20
size=3D3></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT =
size=3D3>ifcrypt::~ifcrypt( void=20
)<BR>{<BR> // This one is emty. Forfuture changes, it is defined=20
anyway.<BR>}</FONT></FONT><FONT size=3D3></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT size=3D3>char =
ifcrypt::decryptchar( char=20
* chars )<BR>{<BR></FONT></FONT><FONT size=3D3><FONT color=3D#000000=20
face=3DArial></FONT>// Sorry, couldn't give this. =
CLASSIFIED</FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT =
size=3D3>}</FONT></FONT><FONT=20
size=3D3></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT size=3D3>ifcrypt::ifcrypt( =
void=20
)<BR>{<BR> fileopen=3Dfalse;<BR>}</FONT></FONT><FONT=20
size=3D3></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT size=3D3>ifcrypt::ifcrypt( =
char *=20
filename, const char * _pasword )<BR>{<BR> open( filename, =
_pasword=20
);<BR>}</FONT></FONT><FONT size=3D3></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT size=3D3>void =
ifcrypt::open( char *=20
filename, const char * _pasword )<BR>{<BR> char * dummy =3D (char =
*)malloc(=20
strlen( CRYPT_STRING )+1 ); // Crypt_string is a identifier string with=20
#define.</FONT></FONT><FONT size=3D3></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT size=3D3> file =3D =
::open( filename,=20
O_BINARY ); // open is included from the library</FONT></FONT></DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT size=3D3> pasword =
=3D (char=20
*)malloc( strlen( _pasword )+1 );<BR> strcpy( pasword, _pasword=20
);</FONT></FONT><FONT size=3D3></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT size=3D3> readline( =
dummy, strlen(=20
CRYPT_STRING ));</FONT></FONT><FONT size=3D3></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT size=3D3> if( =
strcmp( dummy,=20
CRYPT_STRING )=3D=3D0 )<BR> fileopen=3Dtrue;<BR> =
else<BR> {<BR> =
fileopen=3Dfalse;<BR> =20
::close( file );<BR> }</FONT></FONT><FONT =
size=3D3></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT size=3D3> free( =
dummy=20
);</FONT></FONT><FONT size=3D3></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT size=3D3> =20
return;<BR>}</FONT></FONT><FONT size=3D3></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT size=3D3>void =
ifcrypt::close( void=20
)<BR>{<BR> ::close( file );<BR> free( pasword=20
);<BR>}</FONT></FONT><FONT size=3D3></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT size=3D3>void =
ifcrypt::readline( char *=20
line, int len, char endchar )<BR>{<BR> char chars[2];<BR> =
char=20
returned;</FONT></FONT><FONT size=3D3></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT size=3D3> int=20
i;</FONT></FONT><FONT size=3D3></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT size=3D3> for( =
i=3D0; i<len; i++=20
)<BR> {<BR> read( file, chars, 2=20
);<BR> line[i] =3D decryptchar( chars =
);</FONT></FONT><FONT=20
size=3D3></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT =
size=3D3> if(=20
line[i]=3D=3Dendchar )<BR> =
{<BR> =20
line[i+1]=3D0;<BR> =
break;<BR> =20
}<BR> }</FONT></FONT><FONT size=3D3></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT size=3D3> =20
line[len]=3D0;<BR>}</FONT></FONT><FONT size=3D3></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT size=3D3>void =
ifcrypt::readlen( char *=20
line, int len )<BR>{<BR> char chars[2];<BR> char=20
returned;</FONT></FONT><FONT size=3D3></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT size=3D3> int=20
i;</FONT></FONT><FONT size=3D3></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT size=3D3> for( =
i=3D0; i<len; i++=20
)<BR> {<BR> read( file, chars, 2=20
);<BR> line[i] =3D decryptchar( chars );<BR> =20
}<BR>}</FONT></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT =
size=3D3></FONT></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT =
size=3D3></FONT></FONT> </DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT =
size=3D3>Thanks,</FONT></FONT></DIV>
<DIV><FONT color=3D#000000 face=3DArial><FONT =
size=3D3></FONT></FONT> </DIV>
<DIV><FONT face=3DArial>Pieter van Ginkel,</FONT></DIV>
<DIV><FONT face=3DArial></FONT> </DIV>
<DIV><FONT face=3DArial>the Netherlands.</FONT></DIV>
<DIV><FONT face=3DArial></FONT> </DIV>
<DIV><FONT face=3DArial><A=20
href=3D"mailto:pginkel AT westbrabant DOT net">pginkel AT westbrabant DOT net</A></FONT=
></DIV>
<DIV><FONT face=3DArial></FONT> </DIV>
<DIV><FONT face=3DArial><A=20
href=3D"http://home.westbrabant.net/~pginkel">http://home.westbrabant.net=
/~pginkel</A> =20
(ie40 or higher only!!!)</FONT></DIV></BODY></HTML>
------=_NextPart_000_0004_01BD3578.39E50560--
- Raw text -