- 主题:fileheader转化失败
【 在 viogus@smth.org-SPAM.no (风之精灵*全力搞好听涛) 的大作中提到: 】
: while (fread(&bh, sizeof(struct userec1), 1, fp)) {
: memset(&bhnew, 0, sizeof(struct userec2));
: memcpy(&bhnew, &bh, sizeof(struct userec1));
我ft,这样一搞不就全乱套了嘛!当然要一项一项依次赋值了。你那个结构好前面
就多了一个title项,memcpy了当然就后面的项全都错位了。
: bhnew.userdefine[1] = -1;
: bhnew.notedate = bh.notedate;
: bhnew.noteline = bh.noteline;
: bhnew.notemode = bh.notemode;
: bhnew.exittime = bh.exittime;
: bhnew.usedspace = bh.usedspace;
: fwrite(&bhnew, sizeof(struct userec2), 1, fp2);
: : ...................
--
struct userec1 { /* Structure used to hold information in */
char userid[IDLEN + 2]; /* PASSFILE */
char flags[2];
time_t firstlogin;
char lasthost[16];
unsigned int numlogins;
unsigned int numposts;
struct userec2 { /* Structure used to hold information in */
char userid[IDLEN + 2]; /* PASSFILE */
char flags; /*一些标志,戒网,版面排序之类的 */
unsigned char title; /*用户级别 */
time_t firstlogin;
char lasthost[16];
unsigned int numlogins;
unsigned int numposts;
仔细看看这里直接memcpy userec1->userec2 会有什么后果。
【 在 F1yingFish@smth.org-SPAM.no (F.Fish|人生如梦·我心依旧) 的大作中提到: 】
: 应该要加上
: bhnew.flags = bh.flags[0];
: bhnew.title = 0;
: 吧
: 【 在 atppp@bbs.stanford.edu-SPAM.no (Big Mouse) 的大作中提到: 】
: : 我ft,这样一搞不就全乱套了嘛!当然要一项一项依次赋值了。你那个结构好前面
: : 就多了一个title项,memcpy了当然就后面的项全都错位了。
: ※ 来源:·BBS 水木清华站 smth.org·[FROM: 219.224.195.*]
--
FROM 219.224.195.*
恩,不好意思我看错了,嘿嘿。你说的有道理,不过还是不确定到底是不是这个问题。
【 在 FlyingFish@coa.cn-bbs.org (人生如梦|抓紧剩下的时间好好工作) 的大作中提到: 】
: 应该不会错位吧
: char 和 unsigned char变量都只占一个字节的啊
: 【 在 atppp@bbs.stanford.edu-SPAM.no (Big Mouse) 的大作中提到: 】
: : 标 题: Re: fileheader转化失败
: : 发信站: 牧场物语 (Sat May 8 08:35:15 2004)
: : 转信站: COA!news.happynet.org!maily.cic.tsinghua.edu.cn!news.bylinux.net!Stanfo
: : struct userec1 { /* Structure used to hold information in */
: : char userid[IDLEN + 2]; /* PASSFILE */
: : char flags[2];
: : time_t firstlogin;
: ...................
--
嘿嘿,解决问题之后跟我们说说吧:)
【 在 FlyingFish@coa.cn-bbs.org (人生如梦|抓紧剩下的时间好好工作) 的大作中提到: 】
: 我看了一下这边新老版本的.PASSWDS
: 2003.5.10snap包的一个用户占188个字节
: 1.2的占220个字节
: 转换前.PASSWDS占376000个字节
: 转换后占440000个字节
: 总文件大小是正确的
: 出问题的应该是在每个用户信息上,只有192个字节
: 【 在 atppp@bbs.stanford.edu-SPAM.no (Big Mouse) 的大作中提到: 】
: : 恩,不好意思我看错了,嘿嘿。你说的有道理,不过还是不确定到底是不是这个问题。
--
i686上应该都是32bit吧。其实struct有点BT的,像下面这个结构:
struct {
char a;
int b;
char c;
}
如果编译设置了诡异的align优化你sizeof一把这个struct没准出来是12,赫赫。
普通操作都没问题但是memcpy类似结构就会出问题。所以那个转换程序虽然用memcpy
没啥问题但是我觉得这是放弃portability的一种做法。
【 在 FlyingFish@coa.cn-bbs.org (人生如梦|抓紧剩下的时间好好工作) 的大作中提到: 】
: Linux下的int和unsigned int都是32bit的?比较奇怪的说
: 【 在 atppp@bbs.stanford.edu-SPAM.no (Big Mouse) 的大作中提到: 】
: : 嘿嘿,解决问题之后跟我们说说吧:)
--
[bbs@localhost testmisc]$ cat c.c
#include "stdio.h"
struct abc {
char a;
int b;
char c;
};
int main(int a, char** b) {
printf("%d\n", sizeof(struct abc));
return 0;
}
[bbs@localhost testmisc]$ cc c.c -o c
[bbs@localhost testmisc]$ ./c
12
[bbs@localhost testmisc]$ cc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
[bbs@localhost testmisc]$
【 在 atppp (Big Mouse) 的大作中提到: 】
: i686上应该都是32bit吧。其实struct有点BT的,像下面这个结构:
: struct {
: char a;
: int b;
: char c;
: }
: 如果编译设置了诡异的align优化你sizeof一把这个struct没准出来是12,赫赫。
: 普通操作都没问题但是memcpy类似结构就会出问题。所以那个转换程序虽然用memcpy
: 没啥问题但是我觉得这是放弃portability的一种做法。
: 【 在 FlyingFish@coa.cn-bbs.org (人生如梦|抓紧剩下的时间好好工作) 的大作中提到: 】
: ...................
--
成功了的话在这里bg一下吧:)
现在转信进smth很慢,我们这样跨站侃大山还是蛮好玩的 ^-^
【 在 FlyingFish@coa.cn-bbs.org (人生如梦|抓紧剩下的时间好好工作) 的大作中提到: 】
: 想了一下,发现是这样的
: 新的passwds每220个字节记录一个用户信息,其中前192个字节为有效字节,把userdefin
: e从4字节扩大到8字节,其余相同,所以在192个字节后面加上28个0就可以了。
: 【 在 atppp@bbs.stanford.edu-SPAM.no (Big Mouse) 的大作中提到: 】
: : i686上应该都是32bit吧。其实struct有点BT的,像下面这个结构:
: : struct {
: : char a;
: : int b;
: : char c;
: : }
: ...................
--