D
Daniel Rudy
Hello Everyone,
I've ran into a little snag with the sizeof operator. Can you get the
size of a member inside a struct using sizeof? I looked through the FAQ
and I couldn't find the answer to this one.
Below is the code fragment. Granted it's pretty platform specific.
typedef struct hwata_info_tag
{
char device[20];
char model[40];
char fwrev[8];
char serial[20];
} hwata_info_t;
/* opens the first ata harddisk on the system
and returns information about it. */
int hwata_get_info(hwata_info_t *atainfo)
{
int fd;
int result;
struct ata_params params;
const char device[] = "/dev/ad0";
fd = open(device, O_RDONLY);
if (fd < 0)
{
ERR("open device failed", errno, 1)
return(errno);
}
result = ioctl(fd, IOCATAGPARM, ¶ms);
if (result < 0)
{
ERR("failed to get device information", errno, 1)
return(errno);
}
close(fd);
strlcpy(atainfo->device, device, sizeof(atainfo->device));
strlcpy(atainfo->model, params->model, sizeof(atainfo->model));
strlcpy(atainfo->serial, params->serial, sizeof(atainfo->serial));
strlcpy(atainfo->fwrev, params->revision, sizeof(atainfo->fwrev));
return(0);
}
And here is the compiler result:
strata:/home/dr2867/c/modules 877 $$$ ->./compile hwata hwata.c error.o
syslog.o param.o
Output File: hwata
Input Files:
hwata.c
error.o
syslog.o
param.o
gcc -W -Wall -Wshadow -Wpointer-arith -Wcast-align -Wstrict-prototypes
-Wnested-externs -Wwrite-strings -Wflo
at-equal -Winline -Wtrigraphs -ansi -std=c89 -pedantic -ggdb3 -o hwata
hwata.c error.o syslog.o param.o
hwata.c: In function `hwata_get_info':
hwata.c:82: error: invalid type argument of `->'
hwata.c:83: error: invalid type argument of `->'
hwata.c:84: error: invalid type argument of `->'
strata:/home/dr2867/c/modules 878 $$$ ->
So if this doesn't work, is there another way of doing this?
--
Daniel Rudy
Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m
Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep
I've ran into a little snag with the sizeof operator. Can you get the
size of a member inside a struct using sizeof? I looked through the FAQ
and I couldn't find the answer to this one.
Below is the code fragment. Granted it's pretty platform specific.
typedef struct hwata_info_tag
{
char device[20];
char model[40];
char fwrev[8];
char serial[20];
} hwata_info_t;
/* opens the first ata harddisk on the system
and returns information about it. */
int hwata_get_info(hwata_info_t *atainfo)
{
int fd;
int result;
struct ata_params params;
const char device[] = "/dev/ad0";
fd = open(device, O_RDONLY);
if (fd < 0)
{
ERR("open device failed", errno, 1)
return(errno);
}
result = ioctl(fd, IOCATAGPARM, ¶ms);
if (result < 0)
{
ERR("failed to get device information", errno, 1)
return(errno);
}
close(fd);
strlcpy(atainfo->device, device, sizeof(atainfo->device));
strlcpy(atainfo->model, params->model, sizeof(atainfo->model));
strlcpy(atainfo->serial, params->serial, sizeof(atainfo->serial));
strlcpy(atainfo->fwrev, params->revision, sizeof(atainfo->fwrev));
return(0);
}
And here is the compiler result:
strata:/home/dr2867/c/modules 877 $$$ ->./compile hwata hwata.c error.o
syslog.o param.o
Output File: hwata
Input Files:
hwata.c
error.o
syslog.o
param.o
gcc -W -Wall -Wshadow -Wpointer-arith -Wcast-align -Wstrict-prototypes
-Wnested-externs -Wwrite-strings -Wflo
at-equal -Winline -Wtrigraphs -ansi -std=c89 -pedantic -ggdb3 -o hwata
hwata.c error.o syslog.o param.o
hwata.c: In function `hwata_get_info':
hwata.c:82: error: invalid type argument of `->'
hwata.c:83: error: invalid type argument of `->'
hwata.c:84: error: invalid type argument of `->'
strata:/home/dr2867/c/modules 878 $$$ ->
So if this doesn't work, is there another way of doing this?
--
Daniel Rudy
Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m
Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep