🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.linux.programacion
Article #1330

Re: file descriptor incorrecto

#1330
From: Miguel
Date: Tue, 10 Jan 2006 15:38
35 lines
2280 bytes
El problema estaba en el open. Faltaba un O_WRONLY. La cosa ha quedado asli

int write_log(char *texto,char *strfile)
{
	struct tm *strtime;
	int fd;
	time_t clock;	
	char date[LEN_DATE];
	char *buffer;
		
	/* abrimos el fichero para escritura y lo creamos si no existe */
	if((fd  = open(strfile,O_WRONLY | O_APPEND | O_CREAT, 0644))<0){
		printf("Error al crear el fichero de log\n");
		perror("Error");
		fflush(stdout);
		return ERROR;
	}

	time(&clock);
   	strtime=localtime(&clock);
	strftime(date,LEN_DATE,"< %Y%m%d:%H%M%S > ",strtime);
	buffer = (char *)malloc((strlen(date)+strlen(texto)+1)*sizeof(char));
	buffer[0]=END;
	strcat(buffer,date);
	strcat(buffer,texto);
	buffer[(strlen(date)+strlen(texto))]=NEW_LINE;
	if(write(fd,buffer,strlen(buffer))<0){
		printf("Error al escribir el fichero de log\n");
		perror("Error");
		fflush(stdout);
		close(fd);
		return ERROR;
	}
	close(fd);
}
Technical Details
Message-ID: <8yQwf.650773$E72.5758028@telenews.teleline.es>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed.hal-mli.net!feeder1.hal-mli.net!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!telenews.teleline.es!not-for-mail
References: <y0wwf.643617$E72.5691575@telenews.teleline.es> <dpudir$bg8$1@cagarruta.escomposlinux.org> <8764otkroo.fsf@barad-dur.escomposlinux.org> <dpulih$ebq$1@cagarruta.escomposlinux.org>

Show Full Headers
Complete Article Headers
X-Google-Thread: f86c8,2934154e59ab408e
X-Google-Attributes: gidf86c8,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed.hal-mli.net!feeder1.hal-mli.net!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!telenews.teleline.es!not-for-mail
X-Trace-PostClient-IP: 80.38.95.88
From: Miguel <migueldelrio@terra.es>
User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)
X-Accept-Language: es-es, es
MIME-Version: 1.0
Newsgroups: es.comp.os.linux.programacion
Subject: Re: file descriptor incorrecto
References: <y0wwf.643617$E72.5691575@telenews.teleline.es> <dpudir$bg8$1@cagarruta.escomposlinux.org> <8764otkroo.fsf@barad-dur.escomposlinux.org> <dpulih$ebq$1@cagarruta.escomposlinux.org>
In-Reply-To: <dpulih$ebq$1@cagarruta.escomposlinux.org>
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 36
Message-ID: <8yQwf.650773$E72.5758028@telenews.teleline.es>
Date: Tue, 10 Jan 2006 15:38:44 GMT
NNTP-Posting-Host: 10.20.31.4
X-Complaints-To: usenet@teleline.es
X-Trace: telenews.teleline.es 1136907524 10.20.31.4 (Tue, 10 Jan 2006 16:38:44 MET)
NNTP-Posting-Date: Tue, 10 Jan 2006 16:38:44 MET
Organization: Terra Networks