Hi, i'm trying to copy a struct into a binary file using the unix instruction write, so i declare and fill the struct "superbloque" in one function "initSB" and then i pass the pointer to another function called bwrite (for block write) which calls write. The problem is that i call the function with a pointer to my struct and write only creates the file and doesn't write anything. I'm pretty sure the problem i have has to do with the pointers because when i execute
in bwrite function it says 1 and should be 48
Here are the important parts of the code:
I know there's a lot of information about this but i've been reading for two days and I can't figure out how to solve the problem.
Thank you very much for your help
Ricardo Galli
Sistemas operativos
Universidad de las Islas Baleares (Palma de Mallorca, Spain)
Dear friends,
can anybody pls tell me how to pass FILE pointer in c. I am so confused .. :confused:
suppose I ve two function
1. file_open()
2. read_line()
I want to call these function from main() function and in file_open() function it will open that file and in read_line()... (5 Replies)
I am using a structure defined as follows
struct gene_square
{
double *x;
double *y;
};I have class, with a member function which is a pointer of this type:
gene_square* m_Genes;I am allocating memory in the constructors like this:
m_Genes = new gene_square;
for (ii=0;... (1 Reply)
I write kernel module with kernel threads using
linux/kthread.h on 2.6.* kernel
I tried to passing data between two kernel threads
with data argument of kthread_run( fun, data , NAME );
but this is not work I dont know why. I tried many possibility
and nothing works.
So I thought that... (0 Replies)
Hi All,
My latest assignment (practice not coursework!) is to write prototype interactive exam/test console application. I've used structs to store the question information (not sure if this was the best way to do it?) and I have the following code that outputs each question and it's possible... (0 Replies)
EDIT: Nevermind, called a friend who is good at this stuff and he figured it out :D
Hi all,
So I'm trying to teach myself to write programs for unix in c. I am currently creating a program, and I need to pass a struct through a pipe, but I can't figure out how.
The struct I want to pass... (0 Replies)
Can someone tell me how to do this?
Just a thought that entered my mind when learning about structs.
First thought was:
struct one
{
struct two;
}
struct two
{
three;
}
one->two->three
would this be how you would access "three"? (1 Reply)
I am trying to work out the best syntax for a relatively simple operation. The goal is to declare an instance of a struct and pass it around to be populated and have the data manipulated. There is an extra wrinkle in that the functions are in different src files.
The main is simple,
#include... (5 Replies)
In a well-known book on the C language, there is an example of an efficient method for using a struct member as an argument to a function. (I'm a C noob, but I believe the correct terminology might be: use call-by-reference instead of call-by-value.) The function is printf.
Anyway, here's a... (5 Replies)
Hello All,
I am having this issue...where I am actually having hard time understanding the problem:
The code is as follows:
#include<iostream.h>
void fxn(char*** var)
{
int i =4;
*var = (char**)malloc(i*sizeof(char*));
for(int j =0; j<4; j++)
{
*var = "name";
cout<<*var;... (6 Replies)
Hi,
I have received an application that stores some properties in a file. The existing struct looks like this:
struct TData
{
UINT uSizeIncludingStrings;
// copy of Telnet data struct
UINT uSize;
// basic properties:
TCHAR szHost; //defined in Sshconfig
UINT iPortNr;
TCHAR... (2 Replies)
Discussion started by: Powerponken
2 Replies
LEARN ABOUT DEBIAN
mb_initm
MBCHAIN(9) BSD Kernel Developer's Manual MBCHAIN(9)NAME
mbchain, mb_init, mb_initm, mb_done, mb_detach, mb_fixhdr, mb_reserve, mb_put_uint8, mb_put_uint16be, mb_put_uint16le, mb_put_uint32be,
mb_put_uint32le, mb_put_int64be, mb_put_int64le, mb_put_mem, mb_put_mbuf, mb_put_uio -- set of functions to build an mbuf chain from various
data types
SYNOPSIS
options LIBMCHAIN
kldload libmchain
#include <sys/param.h>
#include <sys/uio.h>
#include <sys/mchain.h>
int
mb_init(struct mbchain *mbp);
void
mb_initm(struct mbchain *mbp, struct mbuf *m);
void
mb_done(struct mbchain *mbp);
struct mbuf *
mb_detach(struct mbchain *mbp);
int
mb_fixhdr(struct mbchain *mbp);
caddr_t
mb_reserve(struct mbchain *mbp, int size);
int
mb_put_uint8(struct mbchain *mbp, u_int8_t x);
int
mb_put_uint16be(struct mbchain *mbp, u_int16_t x);
int
mb_put_uint16le(struct mbchain *mbp, u_int16_t x);
int
mb_put_uint32be(struct mbchain *mbp, u_int32_t x);
int
mb_put_uint32le(struct mbchain *mbp, u_int32_t x);
int
mb_put_int64be(struct mbchain *mbp, int64_t x);
int
mb_put_int64le(struct mbchain *mbp, int64_t x);
int
mb_put_mem(struct mbchain *mbp, c_caddr_t source, int size, int type);
int
mb_put_mbuf(struct mbchain *mbp, struct mbuf *m);
int
mb_put_uio(struct mbchain *mbp, struct uio *uiop, int size);
DESCRIPTION
These functions are used to compose mbuf chains from various data types. The mbchain structure is used as a working context and should be
initialized with a call to either mb_init() or mb_initm(). It has the following fields:
mb_top (struct mbuf *) A pointer to the top of constructed mbuf chain.
mb_cur (struct mbuf *) A pointer to the currently filled mbuf.
mb_mleft (int) Number of bytes left in the current mbuf.
mb_count (int) Total number of bytes placed in the mbuf chain.
mb_copy (mb_copy_t *) User-defined function to perform a copy into mbuf; useful if any unusual data conversion is necessary.
mb_udata (void *) User-supplied data which can be used in the mb_copy function.
mb_done() function disposes an mbuf chain pointed to by mbp->mb_top field and sets the field to NULL.
mb_detach() function returns the value of mbp->mb_top field and sets its value to NULL.
mb_fixhdr() recalculates the length of an mbuf chain and updates the m_pkthdr.len field of the first mbuf in the chain. It returns the cal-
culated length.
mb_reserve() ensures that the object of the length specified by the size argument will fit in the current mbuf (mbuf allocation is performed
if necessary), and advances all pointers as if the real data was placed. Returned value will point to the beginning of the reserved space.
Note that the size of the object should not exceed MLEN bytes.
All mb_put_*() functions perform an actual copy of the data into mbuf chain. Functions which have le or be suffixes will perform conversion
to the little- or big-endian data formats.
mb_put_mem() function copies size bytes of data specified by the source argument to an mbuf chain. The type argument specifies the method
used to perform a copy, and can be one of the following:
MB_MSYSTEM Use bcopy() function.
MB_MUSER Use copyin(9) function.
MB_MINLINE Use an ``inline'' loop which does not call any function.
MB_MZERO Do not copy any data, but just fill the destination with zero bytes.
MB_MCUSTOM Call function specified by the mbp->mb_copy field.
RETURN VALUES
All int functions except mb_fixhdr() return zero if successful and an error code otherwise.
Note: after failure of any function, an mbuf chain is left in the broken state, and only mb_done() function can safely be called to destroy
it.
EXAMPLES
struct mbchain *mbp;
struct mbuf *m;
mb_init(mbp);
mb_put_uint8(mbp, 33);
mb_put_uint16le(mbp, length);
m = m_copym(mbp->mb_top, 0, M_COPYALL, M_WAIT);
send(m);
mb_done(mbp);
SEE ALSO mbuf(9), mdchain(9)AUTHORS
This manual page was written by Boris Popov <bp@FreeBSD.org>.
BSD February 20, 2001 BSD