🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #4094

Turbo C and ^Z's

#4094
From: Otto J. Makela
Date: Thu, 03 Jan 1991 11:57
46 lines
1963 bytes
In a fit of desperation, I wrote the following code to get rid of trailing
SUB's (^Z's, 0x1A) from MeSsy-DOS files, to make porting programs from Unix
easier... what am I doing wrong ?  Or is it the compiler (I tried compiling
this with an ancient Turbo C 2.0) ?  I've made similar code to work on Manx
Aztec C86 4.10d (a nice compiler, but sadly out of date).
--
#include	<stdio.h>
#include	<fcntl.h>

/*
**	MeSsy-DOS kludge for fopen-append
*/
FILE *fopena(filename)
char *filename;	{
	FILE *f;

	if(f=fopen(filename,"a+b"))	{
		fseek(f,-1L,SEEK_END);
		while(fgetc(f)==0x1A) fseek(f,-2L,SEEK_CUR);
			/* This is needed to clear stdio buffering */
		fseek(f,ftell(f),SEEK_SET);
			/* Then set text mode on the stream */
		setmode(fileno(f),O_TEXT);
	}
	return f;
}

main(argc,argv)
int argc;
char *argv[];	{
	FILE *f;

	if(argc<2)
		fprintf(stderr,"usage: %s file_to_append_to\n",*argv);
	else if(f=fopena(argv[1]))	{
		fprintf(f,"This is the appended text.\n");
		fclose(f);
	} else
		fprintf(stderr,"%s: could not open %s for append\n",
			*argv,argv[1]);
}
--
   /* * * Otto J. Makela <otto@jyu.fi> * * * * * * * * * * * * * * * * * * */
  /* Phone: +358 41 613 847, BBS: +358 41 211 562 (CCITT, Bell 24/12/300) */
 /* Mail: Kauppakatu 1 B 18, SF-40100 Jyvaskyla, Finland, EUROPE         */
/* * * Computers Rule 01001111 01001011 * * * * * * * * * * * * * * * * */
Technical Details
Message-ID: <OTTO.91Jan3125711@tukki.jyu.fi>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!news.funet.fi!tukki.jyu.fi!jyu.fi!otto

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!news.funet.fi!tukki.jyu.fi!jyu.fi!otto
From: otto@tukki.jyu.fi (Otto J. Makela)
Newsgroups: comp.os.msdos.programmer,comp.lang.c
Subject: Turbo C and ^Z's
Message-ID: <OTTO.91Jan3125711@tukki.jyu.fi>
Date: 3 Jan 91 11:57:11 GMT
Sender: news@tukki.jyu.fi (News articles)
Followup-To: comp.os.msdos.programmer
Organization: Turing Police, Criminal AI section
Lines: 46
Nntp-Posting-Host: jyu.fi