UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » C
  • » ^M characters introduced while file transfer using C program

#1 2016-03-21 01:35 PM

useless79
Member
Registered: 2011-10-10
Posts: 30

^M characters introduced while file transfer using C program

Hi,

I have written a server program in C which reads and saves a large file send by a web browser chunk by chunk. While file transfer is done I see unwanted carriage returns  ^M in the transferred file.
My server programs runs on the Linux and file is transferred by a web browser installed in windows using HTTP POST over the network. On server I am using named pipe for receiving
and writing chunks to a file in Linux. Is there any way to remove ^M while file transfer is in progress? I can not wait till the whole file is transferred and then running a dos2unix like utility. I am using
O_RDWR flag while opening named pipe sender end in server.

open(named_pipe_path, O_RDWR)





Thanks in advance.

Offline

#2 2016-03-21 07:06 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,829
Website

Re: ^M characters introduced while file transfer using C program

Sure, just have your receiver strip the CRs before writing to the file...  Use strchr() or just scan through the data looking for the CRs, then memmove() the rest of the string down over them to overwrite them...  This assumes the file data doesn't contain spurious CRs which appear in the middle of lines which you need to retain...  If it does, you'll have to use strstr() or something to look for "\r\n" together, then just overwrite the CR...  And, of course, this will only ever work for text files; if you try stripping CRs from a binary, you're going to end up with a corrupted binary file!

Offline

  • Index
  • » C
  • » ^M characters introduced while file transfer using C program

Board footer

Powered by FluxBB