Sponsored Content
Full Discussion: File read/ write operation
Operating Systems Linux File read/ write operation Post 302425275 by xs2punit on Thursday 27th of May 2010 02:24:41 PM
Old 05-27-2010
Well I do not wish to use IPC at this time.
So without that it is not possible, right?

Code:
 while (cgiFormFileRead(file, b, sizeof(b), &got_count) == cgiFormSuccess)
        {
        fptr = fopen("progress_bar.txt", "w");
        fwrite(b,sizeof(char),got_count,output);
        i++;
                if(i == inc && j<=100)
                {
                fprintf(fptr, "%d" ,j);
                fseek(fptr, 0, SEEK_SET);
                i = 0;
                //fflush(fptr);
                fclose(fptr);
                j++;
                }
        }

So, my ajax reads the text file after every 1 sec or so, however the data is not available until whole file is written by the CGI. Any suggestion?

---------- Post updated at 01:24 PM ---------- Previous update was at 01:11 PM ----------

No I am using C.

Last edited by Scott; 05-27-2010 at 03:17 PM.. Reason: Fixed code tag
 

10 More Discussions You Might Find Interesting

1. IP Networking

how do you get to know if the write operation was succesful.

how do you get to know if the write operation for writing to a socket was succesful was succesful. (3 Replies)
Discussion started by: arjunjag
3 Replies

2. Shell Programming and Scripting

read and write from a file

I have tried to show the file name whose size is greater than 200 byte in current directory. Please help me. ls -l | tr -s " " " " | cut -f 5,9 -d " " >out.txt #set -a x `cat out.txt` i=0 `cat out.txt` | while do read x echo $x #re=200 j=0 if }" < "200" ] then echo $j j=`expr $j... (2 Replies)
Discussion started by: rinku
2 Replies

3. UNIX for Dummies Questions & Answers

Simultaneous file read operation

Hi All, I need information on file handling in UNIX enviornment. If in UNIX enviornment I have two process.. P1 P2 Both accessing the same file simultaneosuly(read operation).. Suppose P1 opened the file in read mode first and started reading the file.. Then P2 opens the same file in... (5 Replies)
Discussion started by: chibob
5 Replies

4. UNIX for Dummies Questions & Answers

Write/read to file descriptors

Is it possible to write to file descriptor 0 and read from 1 or 2? How could this be implemented? (3 Replies)
Discussion started by: machshev
3 Replies

5. Solaris

monitoring multipath IO for read and write operation

Hi Folks, I would like to monitor multipath IO on solaris for write and read operations. Does "sar -d" include multipath IO information along with other block devices ? Thanks, Faizan. (0 Replies)
Discussion started by: sifaizan
0 Replies

6. IP Networking

read/write,write/write lock with smbclient fails

Hi, We have smb client running on two of the linux boxes and smb server on another linux system. During a backup operation which uses smb, read of a file was allowed while write to the same file was going on.Also simultaneous writes to the same file were allowed.Following are the settings in the... (1 Reply)
Discussion started by: swatidas11
1 Replies

7. Shell Programming and Scripting

Transferring file write operation to another host

I have a process running on two hosts in Active/Standby mode. Process running on active machine is handling the traffic while process running on Standby machine is sitting idle. We have a debugging mechanism in which logs are generated on local machine. When logging is enabled then process running... (1 Reply)
Discussion started by: akhilonnet
1 Replies

8. Shell Programming and Scripting

Grab data between 2 keywords any do an array operation and write the file intact

Hi Unix Gurus, I need to grep for a block that is between a start and end keyword and then in between I need to find and replace a keyword. for eg: I need to search between Test = 000; and Test = 000; and find K9 and replace with M9 INPUT FILE Define { Replace = K9; Test =... (6 Replies)
Discussion started by: naveen@
6 Replies

9. Shell Programming and Scripting

File Read and Write

I have got a file in following format: AAAAAAA BBBBBBBB CCCCCCC DDDDDDD I am trying to read this file and out put it in following format: AAAAAAA,BBBBBBB,CCCCCCC,DDDDDD Preferred method is shell or Perl. Any help appreciated. (11 Replies)
Discussion started by: Araoki
11 Replies

10. Shell Programming and Scripting

Read and write in the file

Hello Guys, How all are doing? I have an issue in Unix and want help from all of you I have a file in UNIX which it read by line by line , If at the end of line '0' is written the it should fetch that line into another file and change '0' to '1' and If at the end of line '1' is written then it... (10 Replies)
Discussion started by: adisky123
10 Replies
iconv(3C)						   Standard C Library Functions 						 iconv(3C)

NAME
iconv - code conversion function SYNOPSIS
Default #include <iconv.h> extern size_t iconv(iconv_t cd, const char **restrict inbuf, size_t *restrict inbytesleft, char **restrict outbuf, size_t *restrict out- bytesleft); SUSv3 #include <iconv.h> size_t iconv(iconv_t cd, char **restrict inbuf, size_t *restrict inbytesleft, char **restrict outbuf, size_t *restrict outbytesleft); DESCRIPTION
The iconv() function converts the sequence of characters from one code set, in the array specified by inbuf, into a sequence of corre- sponding characters in another code set, in the array specified by outbuf. The code sets are those specified in the iconv_open() call that returned the conversion descriptor, cd. The inbuf argument points to a variable that points to the first character in the input buffer and inbytesleft indicates the number of bytes to the end of the buffer to be converted. The outbuf argument points to a variable that points to the first available byte in the output buffer and outbytesleft indicates the number of the available bytes to the end of the buffer. For state-dependent encodings, the conversion descriptor cd is placed into its initial shift state by a call for which inbuf is a null pointer, or for which inbuf points to a null pointer. When iconv() is called in this way, and if outbuf is not a null pointer or a pointer to a null pointer, and outbytesleft points to a positive value, iconv() will place, into the output buffer, the byte sequence to change the output buffer to its initial shift state. If the output buffer is not large enough to hold the entire reset sequence, iconv() will fail and set errno to E2BIG. Subsequent calls with inbuf as other than a null pointer or a pointer to a null pointer cause the conversion to take place from the current state of the conversion descriptor. If a sequence of input bytes does not form a valid character in the specified code set, conversion stops after the previous successfully converted character. If the input buffer ends with an incomplete character or shift sequence, conversion stops after the previous success- fully converted bytes. If the output buffer is not large enough to hold the entire converted input, conversion stops just prior to the input bytes that would cause the output buffer to overflow. The variable pointed to by inbuf is updated to point to the byte following the last byte successfully used in the conversion. The value pointed to by inbytesleft is decremented to reflect the number of bytes still not converted in the input buffer. The variable pointed to by outbuf is updated to point to the byte following the last byte of converted out- put data. The value pointed to by outbytesleft is decremented to reflect the number of bytes still available in the output buffer. For state-dependent encodings, the conversion descriptor is updated to reflect the shift state in effect at the end of the last successfully converted byte sequence. If iconv() encounters a character in the input buffer that is legal, but for which an identical character does not exist in the target code set, iconv() performs an implementation-defined conversion on this character. RETURN VALUES
The iconv() function updates the variables pointed to by the arguments to reflect the extent of the conversion and returns the number of non-identical conversions performed. If the entire string in the input buffer is converted, the value pointed to by inbytesleft will be 0. If the input conversion is stopped due to any conditions mentioned above, the value pointed to by inbytesleft will be non-zero and errno is set to indicate the condition. If an error occurs iconv() returns (size_t) -1 and sets errno to indicate the error. ERRORS
The iconv() function will fail if: EILSEQ Input conversion stopped due to an input byte that does not belong to the input code set. E2BIG Input conversion stopped due to lack of space in the output buffer. EINVAL Input conversion stopped due to an incomplete character or shift sequence at the end of the input buffer. The iconv() function may fail if: EBADF The cd argument is not a valid open conversion descriptor. EXAMPLES
Example 1: Using the iconv() Functions The following example uses the iconv() functions: #include <stdio.h> #include <errno.h> #include <string.h> #include <iconv.h> #include <stdlib.h> /* * For state-dependent encodings, changes the state of the conversion * descriptor to initial shift state. Also, outputs the byte sequence * to change the state to initial state. * This code is assuming the iconv call for initializing the state * won't fail due to lack of space in the output buffer. */ #define INIT_SHIFT_STATE(cd, fptr, ileft, tptr, oleft) { fptr = NULL; ileft = 0; tptr = to; oleft = BUFSIZ; (void) iconv(cd, &fptr, &ileft, &tptr, &oleft); (void) fwrite(to, 1, BUFSIZ - oleft, stdout); } int main(int argc, char **argv) { iconv_t cd; char from[BUFSIZ], to[BUFSIZ]; char *from_code, *to_code; char *tptr; const char *fptr; size_t ileft, oleft, num, ret; if (argc != 3) { (void) fprintf(stderr, "Usage: %s from_codeset to_codeset\n", argv[0]); return(1); } from_code = argv[1]; to_code = argv[2]; cd = iconv_open((const char *)to_code, (const char *)from_code); if (cd == (iconv_t)-1) { /* * iconv_open failed */ (void) fprintf(stderr, "iconv_open(%s, %s) failed\n", to_code, from_code); return(1); } ileft = 0; while ((ileft += (num = fread(from + ileft, 1, BUFSIZ - ileft, stdin))) > 0) { if (num == 0) { /* * Input buffer still contains incomplete character * or sequence. However, no more input character. */ /* * Initializes the conversion descriptor and outputs * the sequence to change the state to initial state. */ INIT_SHIFT_STATE(cd, fptr, ileft, tptr, oleft); (void) iconv_close(cd); (void) fprintf(stderr, "Conversion error\n"); return(1); } fptr = from; for (;;) { tptr = to; oleft = BUFSIZ; ret = iconv(cd, &fptr, &ileft, &tptr, &oleft); if (ret != (size_t)-1) { /* * iconv succeeded */ /* * Outputs converted characters */ (void) fwrite(to, 1, BUFSIZ - oleft, stdout); break; } /* * iconv failed */ if (errno == EINVAL) { /* * Incomplete character or shift sequence */ /* * Outputs converted characters */ (void) fwrite(to, 1, BUFSIZ - oleft, stdout); /* * Copies remaining characters in input buffer * to the top of the input buffer. */ (void) memmove(from, fptr, ileft); /* * Tries to fill input buffer from stdin */ break; } else if (errno == E2BIG) { /* * Lack of space in output buffer */ /* * Outputs converted characters */ (void) fwrite(to, 1, BUFSIZ - oleft, stdout); /* * Tries to convert remaining characters in * input buffer with emptied output buffer */ continue; } else if (errno == EILSEQ) { /* * Illegal character or shift sequence */ /* * Outputs converted characters */ (void) fwrite(to, 1, BUFSIZ - oleft, stdout); /* * Initializes the conversion descriptor and * outputs the sequence to change the state to * initial state. */ INIT_SHIFT_STATE(cd, fptr, ileft, tptr, oleft); (void) iconv_close(cd); (void) fprintf(stderr, "Illegal character or sequence\n"); return(1); } else if (errno == EBADF) { /* * Invalid conversion descriptor. * Actually, this shouldn't happen here. */ (void) fprintf(stderr, "Conversion error\n"); return(1); } else { /* * This errno is not defined */ (void) fprintf(stderr, "iconv error\n"); return(1); } } } /* * Initializes the conversion descriptor and outputs * the sequence to change the state to initial state. */ INIT_SHIFT_STATE(cd, fptr, ileft, tptr, oleft); (void) iconv_close(cd); return(0); } FILES
/usr/lib/iconv/*.so conversion modules for 32-bit /usr/lib/iconv/sparcv9/*.so conversion modules for 64-bit sparc /usr/lib/iconv/amd64/*.so conversion modules for 64-bit amd64 /usr/lib/iconv/geniconvtbl/binarytables/*.bt conversion binary tables ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
geniconvtbl(1), iconv(1), iconv_close(3C), iconv_open(3C), geniconvtbl(4), attributes(5), iconv(5), iconv_unicode(5), standards(5) SunOS 5.10 6 Oct 2004 iconv(3C)
All times are GMT -4. The time now is 01:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy