akaedu008 于 2008-08-17 18:23:19发表:
manpage 很好用,不用去任何论坛
black_billow08 于 2008-08-17 17:42:59发表:
执行后的输出,除上面贴出的部分,上面还有很多比较凌乱的东西,copy不下来,需要截屏吗?要不大家ftp虚拟机里帮我也测试一下啊,十分感谢!
black_billow08 于 2008-08-17 17:38:45发表:
这是函数mmap()帮助里的一个例子: #include #include #include #include #include #include int main (int argc, char *argv[]) { char *addr; int fd; struct stat sb; off_t offset, pa_offset; size_t length; ssize_t s; if ((argc < 3 || argc > 4) == 0) { fprintf(stderr, "%s file offset [length]\n", argv[0] ); exit(EXIT_FAILURE); } fd = open(argv[1], O_RDONLY); if (fd == -1) { perror("open"); exit(EXIT_FAILURE); } if (fstat(fd, &sb) == -1){ /* To obtain file size*/ perror("fstat"); exit(EXIT_FAILURE); } offset = atoi(argv[2]); pa_offset = offset & ~(sysconf(_SC_PAGE_SIZE) -1); /* Offset for mmap() must be page aligned */ if (offset >= sb.st_size){ fprintf(stderr, "offset is past end of file\n"); exit(EXIT_FAILURE); } if (argc == 4) { length = atoi(argv[3]); if (offset + length > sb.st_size) length = sb.st_size - offset; /* Can’t display bytes past end of file */ } else { /* No length arg ==> display to end of file */ length = sb.st_size - offset; } addr = mmap(NULL, length + offset - pa_offset, PROT_READ, MAP_PRIVATE, fd, pa_offset); if (addr == MAP_FAILED) { perror("mmap"); exit(EXIT_FAILURE); } s = write(STDOUT_FILENO, addr + offset - pa_offset, length); if (s != length) { if (s == -1) perror("write"); else fprintf(stderr, "partial write"); exit(EXIT_FAILURE); } exit(EXIT_SUCCESS); } /* main */ 我编译成功之后,按如下执行: ./mmap_test mmap_test bill.c 1024 1024 输出了一堆乱七八糟的东西 我copy下面,不过有一部分copy不下来: call_gmon_startcrtstuff.c__CTOR_LIST____DTOR_LIST____JCR_LIST__dtor_idx.5647completed.5645__do_global_dtors_auxframe_dummy__CTOR_END____FRAME_END____JCR_END____do_global_ctors_auxmmap_test.c_GLOBAL_OFFSET_TABLE___init_array_end__init_array_start_DYNAMICdata_startopen@@GLIBC_2.0mmap@@GLIBC_2.0__libc_csu_finisysconf@@GLIBC_2.0_start__gmon_start___Jv_RegisterClasses_fp_hw_fini__fstatwrite@@GLIBC_2.0__libc_start_main@@GLIBC_2.0perror@@GLIBC_2.0_IO_stdin_used__data_startstderr@@GLIBC_2.0__dso_handle__DTOR_END____libc_csu_initatoi@@GLIBC_2.0fwrite@@GLIBC_2.0fprintf@@GLIBC_2.0__bss_start_endfstat__fxstat@@GLIBC_2.0_edataexit@@GLIBC_2.0__i686.get_pc_thunk.bxmain_init[root@superIDH test]# 请各位指点一下啊,是不是我指的参数不对啊? 十分感谢!
lyq617617 于 2008-08-17 17:18:18发表:
把问题直接贴出来好了,会的人一定会帮助你的.[ 本帖最后由 lyq617617 于 2008-8-17 17:19 编辑 ]
black_billow08 于 2008-08-17 17:11:24发表:
现在可以问你一个问题吗? 谢谢
lyq617617 于 2008-08-17 16:49:01发表:
引用:原帖由 black_billow08 于 2008-8-17 14:34 发表 我是linux下c语言初级学习者,平时会有很多问题,请问:谁知道哪论坛交流,或者说请教问题回复比较快? 谢谢!
shenshen 于 2008-08-17 15:45:21发表:
:0)1
shenshen 于 2008-08-17 15:45:14发表:
找我好了!愿意效劳
lizewen 于 2008-08-17 15:39:44发表:
既来之,则安之。
akaedu008 于 2008-08-17 18:23:19发表:
manpage 很好用,不用去任何论坛
black_billow08 于 2008-08-17 17:42:59发表:
执行后的输出,除上面贴出的部分,上面还有很多比较凌乱的东西,copy不下来,需要截屏吗?要不大家ftp虚拟机里帮我也测试一下啊,十分感谢!
black_billow08 于 2008-08-17 17:38:45发表:
这是函数mmap()帮助里的一个例子:
#include
#include
#include
#include
#include
#include
int main (int argc, char *argv[])
{
char *addr;
int fd;
struct stat sb;
off_t offset, pa_offset;
size_t length;
ssize_t s;
if ((argc < 3 || argc > 4) == 0) {
fprintf(stderr, "%s file offset [length]\n", argv[0] );
exit(EXIT_FAILURE);
}
fd = open(argv[1], O_RDONLY);
if (fd == -1) {
perror("open");
exit(EXIT_FAILURE);
}
if (fstat(fd, &sb) == -1){ /* To obtain file size*/
perror("fstat");
exit(EXIT_FAILURE);
}
offset = atoi(argv[2]);
pa_offset = offset & ~(sysconf(_SC_PAGE_SIZE) -1);
/* Offset for mmap() must be page aligned */
if (offset >= sb.st_size){
fprintf(stderr, "offset is past end of file\n");
exit(EXIT_FAILURE);
}
if (argc == 4) {
length = atoi(argv[3]);
if (offset + length > sb.st_size)
length = sb.st_size - offset;
/* Can’t display bytes past end of file */
} else { /* No length arg ==> display to end of file */
length = sb.st_size - offset;
}
addr = mmap(NULL, length + offset - pa_offset, PROT_READ,
MAP_PRIVATE, fd, pa_offset);
if (addr == MAP_FAILED) {
perror("mmap");
exit(EXIT_FAILURE);
}
s = write(STDOUT_FILENO, addr + offset - pa_offset, length);
if (s != length) {
if (s == -1)
perror("write");
else
fprintf(stderr, "partial write");
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
} /* main */
我编译成功之后,按如下执行:
./mmap_test mmap_test bill.c 1024 1024
输出了一堆乱七八糟的东西
我copy下面,不过有一部分copy不下来:
call_gmon_startcrtstuff.c__CTOR_LIST____DTOR_LIST____JCR_LIST__dtor_idx.5647completed.5645__do_global_dtors_auxframe_dummy__CTOR_END____FRAME_END____JCR_END____do_global_ctors_auxmmap_test.c_GLOBAL_OFFSET_TABLE___init_array_end__init_array_start_DYNAMICdata_startopen@@GLIBC_2.0mmap@@GLIBC_2.0__libc_csu_finisysconf@@GLIBC_2.0_start__gmon_start___Jv_RegisterClasses_fp_hw_fini__fstatwrite@@GLIBC_2.0__libc_start_main@@GLIBC_2.0perror@@GLIBC_2.0_IO_stdin_used__data_startstderr@@GLIBC_2.0__dso_handle__DTOR_END____libc_csu_initatoi@@GLIBC_2.0fwrite@@GLIBC_2.0fprintf@@GLIBC_2.0__bss_start_endfstat__fxstat@@GLIBC_2.0_edataexit@@GLIBC_2.0__i686.get_pc_thunk.bxmain_init[root@superIDH test]#
请各位指点一下啊,是不是我指的参数不对啊?
十分感谢!
lyq617617 于 2008-08-17 17:18:18发表:
把问题直接贴出来好了,会的人一定会帮助你的.
[ 本帖最后由 lyq617617 于 2008-8-17 17:19 编辑 ]
black_billow08 于 2008-08-17 17:11:24发表:
现在可以问你一个问题吗?
谢谢
lyq617617 于 2008-08-17 16:49:01发表:
红联是我见过的请教问题回复最快的论坛,不是打广告!
一般发帖几分钟后就会有人看到帖子,同时在线人数上千,适合在线学习交流!
shenshen 于 2008-08-17 15:45:21发表:
:0)1
shenshen 于 2008-08-17 15:45:14发表:
找我好了!愿意效劳
lizewen 于 2008-08-17 15:39:44发表:
既来之,则安之。