🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

file descriptor incorrecto

#1324
From: Miguel
Date: Mon, 09 Jan 2006 16:17
38 lines
1951 bytes
hola,

estoy probando el siguiente c�digo y errno me dice al llamar a write que 
el fd no es correcto. �qu� estoy haciendo mal?

gracias

un saludo


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

	time(&clock);
   	strtime=localtime(&clock);
	strftime(date,LEN_DATE,"%Y%m%d:%H%M%S ",strtime);
	strcat(buffer,date);
	strcat(buffer,texto);
	if(write(fd,buffer,strlen(buffer))<0){
		printf("Error al escribir el fichero de log\n");
		fflush(stdout);
		close(fd);
		return ERROR;
	}
	close(fd);
}
Technical Details
Message-ID: <y0wwf.643617$E72.5691575@telenews.teleline.es>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!pd7cy2so!shaw.ca!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!telenews.teleline.es!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: f86c8,2934154e59ab408e,start
X-Google-Attributes: gidf86c8,public
X-Google-Language: SPANISH,ASCII
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!pd7cy2so!shaw.ca!news-out.newsgroups.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: file descriptor incorrecto
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 39
Message-ID: <y0wwf.643617$E72.5691575@telenews.teleline.es>
Date: Mon, 09 Jan 2006 16:17:34 GMT
NNTP-Posting-Host: 10.20.31.4
X-Complaints-To: usenet@teleline.es
X-Trace: telenews.teleline.es 1136823454 10.20.31.4 (Mon, 09 Jan 2006 17:17:34 MET)
NNTP-Posting-Date: Mon, 09 Jan 2006 17:17:34 MET
Organization: Terra Networks