Sponsored Content
Full Discussion: EOF checking the below
Top Forums Programming EOF checking the below Post 302174230 by shamrock on Monday 10th of March 2008 12:24:13 PM
Old 03-10-2008
Quote:
Originally Posted by ramkrix
Thanks fmurphy for your reply.

if I have a structure defined at the beginning in another prgm instaed of an char array name[20],can I use like this?

struct bio {
char name[20];
int age;
float salary;
}

main()
{
struct bio mydata;
--------
--------
--------

read(fd, &mydata, (size_t) ))

}
How can we use the size_t with structure?

Thanks in Advance..

Ramkrix
fpmurphy's post clearly says that size_t is a typedef for an unsigned long. Declare a variable of that type as a structure member before using it in the read() call. The (size_t) is the C lang notation for a typecast used when converting from one type to another. Wrap code tags around your program listings.

Code:
struct bio
{
     char name[20];
     int age;
     float salary;
     size_t num_of_bytes_read;
}

main()
{
    read(fd, &mydata, num_of_bytes_read)
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Please help with EOF

Hello, you are an awesome crowd! You answered my last questions, thank you sooo much! I am trying to write a korn shell script that will record the memory my application is using (HP-UX B.11.11) and I have this: if (( $APP > $THRESHOLD )) then echo "Warning message will display" cat... (2 Replies)
Discussion started by: satraver
2 Replies

2. UNIX for Dummies Questions & Answers

Eof

I have written this code: code echo 'Now choose the file or files you want to merge your input with: \c' read filenames filelist="" for file in $filenames; do filelist="$filelist $file" done echo "Now that you've chosen these files ($filelist), please start typing: " until ; do paste -... (2 Replies)
Discussion started by: fiol73
2 Replies

3. Shell Programming and Scripting

Eof

hi, in a shell script i came accross the following bit of code 1.shift $(($OPTIND - 1)) 2.if ; then 3. cat << EOF >&2 4.Usage: $0 lockfilename 5.EOF 6. exit 1 7.fi I am not able to understand the meaning of lines(1,3,5). Can any one of u tell me the purpose of above said lines.... (1 Reply)
Discussion started by: ravi raj kumar
1 Replies

4. UNIX for Dummies Questions & Answers

\n after EOF

Hello all, I have unix file that ends with the following EOF '9999999999' I want to remove the '\n' character after EOF. What is the command that should be included in the script, before sending the file? will this work: $ echo "<99999999999>\c" >> <filename> thanks in advance. (3 Replies)
Discussion started by: priya12
3 Replies

5. Shell Programming and Scripting

What is << EOF

I'm trying to connect to oracle with the following code in the script: checksqlerror{ if echo $1 exit fi } $SQLPLUS username/password@schemaname checksqlerror "failed to connect to oracle" If I'm passing wrong schema name,instead of executing checksqlerror it stops and expects user... (2 Replies)
Discussion started by: BhawanaAggarwal
2 Replies

6. Programming

Eof

How can I write EOF into a file? I tryed to do as follows: size=sizeof(EOF); end_of_file=EOF; write(fdMutexRichieste, &end_of_file, size); But it does non work correctly, becouse in the next cicle (using lseek(..., SEEK_END) of my code it seems to ignore my EOF and use the LAST... (5 Replies)
Discussion started by: DNAx86
5 Replies

7. Shell Programming and Scripting

Until eof do????

Hey! Can I write a routine that allows me to in a txt file check line by line until the end of file? something like until do ---some code--- done maybe it is a stupid question but I never learned shell scripts and I need this :p thanks in advance (1 Reply)
Discussion started by: ruben.rodrigues
1 Replies

8. Shell Programming and Scripting

confused with << EOF EOF

Hi friends , I am confused with << EOF EOF Most of the cases I found sqlplus $db_conn_str << EOF some sql staments EOF another exapmle is #!/bin/sh echo -n 'what is the value? ' read value sed 's/XXX/'$value'/' <<EOF The value is XXX EOF (1 Reply)
Discussion started by: imipsita.rath
1 Replies

9. Shell Programming and Scripting

[Solved] <<EOF error checking

I am trying to check the return status of a command thats encapsulated in an <<EOF #!/bin/ksh set -x xxx() { set -x ls -lt /tmp/jdlkewjdlkewjdlkewjdlewjdlew<<EOT ret=$? EOT echo "ret=$ret" } >>$LOG 2>&1 LOG=/tmp/t2.out rm -rf $LOG echo "Starting process `date... (2 Replies)
Discussion started by: BeefStu
2 Replies

10. SCO

Stop boot system at "Checking protected password and checking subsystem databases"

Hi, (i'm sorry for my english) I'm a problem on boot sco unix 5.0.5 open server. this stop at "Checking protected password and checking subsystem databases" (See this image ) I'm try this: 1) http://www.digipedia.pl/usenet/thread/50/37093/#post37094 2) SCO: SCO Unix - Server hangs... (9 Replies)
Discussion started by: buji
9 Replies
ARCHIVE_READ(3) 					   BSD Library Functions Manual 					   ARCHIVE_READ(3)

NAME
archive_read -- functions for reading streaming archives LIBRARY
Streaming Archive Library (libarchive, -larchive) SYNOPSIS
#include <archive.h> DESCRIPTION
These functions provide a complete API for reading streaming archives. The general process is to first create the struct archive object, set options, initialize the reader, iterate over the archive headers and associated data, then close the archive and release all resources. Create archive object See archive_read_new(3). To read an archive, you must first obtain an initialized struct archive object from archive_read_new(). Enable filters and formats See archive_read_filter(3) and archive_read_format(3). You can then modify this object for the desired operations with the various archive_read_set_XXX() and archive_read_support_XXX() functions. In particular, you will need to invoke appropriate archive_read_support_XXX() functions to enable the corresponding compression and format support. Note that these latter functions perform two distinct operations: they cause the corresponding support code to be linked into your program, and they enable the corresponding auto-detect code. Unless you have specific constraints, you will generally want to invoke archive_read_support_filter_all() and archive_read_support_format_all() to enable auto-detect for all formats and compression types currently supported by the library. Set options See archive_read_set_options(3). Open archive See archive_read_open(3). Once you have prepared the struct archive object, you call archive_read_open() to actually open the archive and prepare it for reading. There are several variants of this function; the most basic expects you to provide pointers to several functions that can provide blocks of bytes from the archive. There are convenience forms that allow you to specify a filename, file descriptor, FILE * object, or a block of mem- ory from which to read the archive data. Note that the core library makes no assumptions about the size of the blocks read; callback func- tions are free to read whatever block size is most appropriate for the medium. Consume archive See archive_read_header(3), archive_read_data(3) and archive_read_extract(3). Each archive entry consists of a header followed by a certain amount of data. You can obtain the next header with archive_read_next_header(), which returns a pointer to an struct archive_entry structure with information about the current archive element. If the entry is a regular file, then the header will be followed by the file data. You can use archive_read_data() (which works much like the read(2) system call) to read this data from the archive, or archive_read_data_block() which provides a slightly more efficient interface. You may prefer to use the higher-level archive_read_data_skip(), which reads and discards the data for this entry, archive_read_data_to_file(), which copies the data to the provided file descriptor, or archive_read_extract(), which recreates the specified entry on disk and copies data from the archive. In particular, note that archive_read_extract() uses the struct archive_entry structure that you provide it, which may differ from the entry just read from the archive. In particular, many applications will want to override the path- name, file permissions, or ownership. Release resources See archive_read_free(3). Once you have finished reading data from the archive, you should call archive_read_close() to close the archive, then call archive_read_free() to release all resources, including all memory allocated by the library. EXAMPLE
The following illustrates basic usage of the library. In this example, the callback functions are simply wrappers around the standard open(2), read(2), and close(2) system calls. void list_archive(const char *name) { struct mydata *mydata; struct archive *a; struct archive_entry *entry; mydata = malloc(sizeof(struct mydata)); a = archive_read_new(); mydata->name = name; archive_read_support_filter_all(a); archive_read_support_format_all(a); archive_read_open(a, mydata, myopen, myread, myclose); while (archive_read_next_header(a, &entry) == ARCHIVE_OK) { printf("%s ",archive_entry_pathname(entry)); archive_read_data_skip(a); } archive_read_free(a); free(mydata); } ssize_t myread(struct archive *a, void *client_data, const void **buff) { struct mydata *mydata = client_data; *buff = mydata->buff; return (read(mydata->fd, mydata->buff, 10240)); } int myopen(struct archive *a, void *client_data) { struct mydata *mydata = client_data; mydata->fd = open(mydata->name, O_RDONLY); return (mydata->fd >= 0 ? ARCHIVE_OK : ARCHIVE_FATAL); } int myclose(struct archive *a, void *client_data) { struct mydata *mydata = client_data; if (mydata->fd > 0) close(mydata->fd); return (ARCHIVE_OK); } SEE ALSO
tar(1), libarchive(3), archive_read_new(3), archive_read_data(3), archive_read_extract(3), archive_read_filter(3), archive_read_format(3), archive_read_header(3), archive_read_open(3), archive_read_set_options(3), archive_util(3), tar(5) HISTORY
The libarchive library first appeared in FreeBSD 5.3. AUTHORS
The libarchive library was written by Tim Kientzle <kientzle@acm.org>. BUGS
Many traditional archiver programs treat empty files as valid empty archives. For example, many implementations of tar(1) allow you to append entries to an empty file. Of course, it is impossible to determine the format of an empty file by inspecting the contents, so this library treats empty files as having a special ``empty'' format. BSD
February 2, 2012 BSD
All times are GMT -4. The time now is 05:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy