[mw-devel] [Git][arthur/mw][master] Use SEEK_* in lseek(2) calls
Andrew Price
welshbyte at sucs.org
Sat Nov 14 15:40:31 GMT 2015
Andrew Price pushed to branch master at Justin Mitchell / mw
Commits:
2b6a2c76 by Andrew Price at 2015-11-14T15:31:53Z
Use SEEK_* in lseek(2) calls
Change scripted with coccinelle:
@rule0@
expression A,B;
@@
- lseek(A, B, 0);
+ lseek(A, B, SEEK_SET);
@rule1@
expression A,B;
@@
- lseek(A, B, 1);
+ lseek(A, B, SEEK_CUR);
@rule2@
expression A,B;
@@
- lseek(A, B, 2);
+ lseek(A, B, SEEK_END);
- - - - -
7 changed files:
- src/client/add.c
- src/client/edit.c
- src/client/mod.c
- src/client/new.c
- src/client/newmain.c
- src/client/read.c
- src/folders.c
Changes:
=====================================
src/client/add.c
=====================================
--- a/src/client/add.c
+++ b/src/client/add.c
@@ -168,7 +168,7 @@ int add_msg(int folnum, struct user *user, int replyto)
free(new);
return(-1);
}else
- lseek(headfile,posn,0);
+ lseek(headfile, posn, SEEK_SET);
while (get_data(headfile,&inreplyto) && inreplyto.Ref<replyto);
if (inreplyto.Ref!=replyto)
{
@@ -372,7 +372,7 @@ int add_msg(int folnum, struct user *user, int replyto)
return(0);
}
size=lseek(tfile,0,2);
- lseek(tfile,0,0);
+ lseek(tfile, 0, SEEK_SET);
buff=(char *)realloc(buff,size);
read(tfile,buff,size);
new->size=size;
@@ -398,9 +398,9 @@ int add_msg(int folnum, struct user *user, int replyto)
Lock_File(data);
new->datafield=lseek(data,0l,2);
- lseek(folderfile,folnum*sizeof(struct folder),0);
+ lseek(folderfile, folnum * sizeof(struct folder), SEEK_SET);
read(folderfile,fol,sizeof(*fol));
- lseek(folderfile,-1*sizeof(struct folder),1);
+ lseek(folderfile, -1 * sizeof(struct folder), SEEK_CUR);
if (!is_moderated(fol,user))
{
new->Ref=fol->last+1;
@@ -408,7 +408,7 @@ int add_msg(int folnum, struct user *user, int replyto)
if (fol->first==0) fol->first=1;
if (replyto>0)
{
- lseek(i,replyposn,0);
+ lseek(i, replyposn, SEEK_SET);
write(i,&inreplyto,sizeof(inreplyto));
}
}else
@@ -421,7 +421,7 @@ int add_msg(int folnum, struct user *user, int replyto)
if (td>0){
printf(_("Warning: Index error, skipping back %ld bytes.\r\n"),td);
- lseek(i,-td,1);
+ lseek(i, -td, SEEK_CUR);
}
if ((write(i,new,sizeof(*new)))<sizeof(*new))
{
=====================================
src/client/edit.c
=====================================
--- a/src/client/edit.c
+++ b/src/client/edit.c
@@ -610,7 +610,7 @@ static void users_lastread(int folnum)
Lock_File(ufile);
while (read(ufile,&usr,sizeof(usr))>0)
{
- lseek(ufile,-1*sizeof(usr),1);
+ lseek(ufile, -1 * sizeof(usr), SEEK_CUR);
usr.lastread[folnum]=0;
usr.folders[0]|=(1<<folnum);
write(ufile,&usr,sizeof(usr));
@@ -763,7 +763,7 @@ void edit_folder(const char *args, const char *name)
afile=openfolderfile(O_RDWR);
Lock_File(afile);
- lseek(afile,folnum*sizeof(struct folder),0);
+ lseek(afile, folnum * sizeof(struct folder), SEEK_SET);
write(afile,&fold,sizeof(struct folder));
Unlock_File(afile);
close(afile);
@@ -793,7 +793,7 @@ void mesg_edit(const char *args, struct folder *folder, int msgno, struct user *
return;
}
buff=(char *)malloc(head.size);
- lseek(text,head.datafield,0);
+ lseek(text, head.datafield, SEEK_SET);
read(text,buff,head.size);
if (!u_god(usr) && !u_mod(usr) && strcasecmp(head.from, usr->record.name))
@@ -866,7 +866,7 @@ void mesg_edit(const char *args, struct folder *folder, int msgno, struct user *
return;
}
size=lseek(tfile,0,2);
- lseek(tfile,0,0);
+ lseek(tfile, 0, SEEK_SET);
buff=(char *)realloc(buff,size);
read(tfile,buff,size);
head.size=size;
@@ -933,7 +933,7 @@ void mesg_edit(const char *args, struct folder *folder, int msgno, struct user *
else
printf(_("What do you want to do ?\n"));
Lock_File(fd);
- lseek(fd,-1*sizeof(head),1);
+ lseek(fd, -1 * sizeof(head), SEEK_CUR);
write(fd,&head,sizeof(head));
Unlock_File(fd);
close(fd);
=====================================
src/client/mod.c
=====================================
--- a/src/client/mod.c
+++ b/src/client/mod.c
@@ -114,7 +114,7 @@ void moderate(void)
{
int foo;
text=(char *)malloc(head.size);
- lseek(tmptext,head.datafield,0);
+ lseek(tmptext, head.datafield, SEEK_SET);
if ((foo=read(tmptext,text,head.size))<head.size)
{
printf(_("only %d of %d bytes read.\n"),foo,head.size);
@@ -127,7 +127,8 @@ void moderate(void)
if (stringcmp(answer,_("approve"),1))
{
Lock_File(f_file);
- lseek(f_file,-1*sizeof(struct folder),1);
+ lseek(f_file, -1 * sizeof(struct folder),
+ SEEK_CUR);
fold.last++;
if (fold.first<=0) fold.first=1;
write(f_file,&fold,sizeof(fold));
=====================================
src/client/new.c
=====================================
--- a/src/client/new.c
+++ b/src/client/new.c
@@ -100,10 +100,10 @@ static int read_new(struct user *user, struct folder *data, int folnum)
}
/* try jumping to expected location */
posn = (urec->lastread[folnum] - data->first + 1) * sizeof(struct Header);
- lseek(indexfile, posn, 0);
+ lseek(indexfile, posn, SEEK_SET);
/* read the article, if failed, or overshot then rewind to start */
if (!get_data(indexfile, &head) || head.Ref > urec->lastread[folnum]) {
- lseek(indexfile,0,0);
+ lseek(indexfile, 0, SEEK_SET);
get_data(indexfile,&head);
}
@@ -151,7 +151,7 @@ static int read_new(struct user *user, struct folder *data, int folnum)
long foo;
foo=lseek(indexfile,0,1);
add_msg(folnum, user, head.Ref);
- lseek(indexfile,foo,0);
+ lseek(indexfile, foo, SEEK_SET);
get_folder_number(data,folnum);
}else
if (stringcmp(tmp,"unsubscribe",5))
=====================================
src/client/newmain.c
=====================================
--- a/src/client/newmain.c
+++ b/src/client/newmain.c
@@ -721,7 +721,7 @@ void c_tidyup(CommandList *cm, int argc, const char **argv, char *args)
{
first=idx.Ref<first?idx.Ref:first;
textbuff=(char *)malloc(idx.size+1);
- lseek(textin,idx.datafield,0);
+ lseek(textin, idx.datafield, SEEK_SET);
read(textin,textbuff,idx.size);
idx.datafield=lseek(textout,0,1);
write(textout,textbuff,idx.size);
=====================================
src/client/read.c
=====================================
--- a/src/client/read.c
+++ b/src/client/read.c
@@ -69,7 +69,7 @@ void display_article(struct Header *tmp, int datafile)
if (tmp->status&(1<<2))
fprintf(output,"Message has a reply.\n");
fprintf(output,"\n");
- lseek(datafile,tmp->datafield,0);
+ lseek(datafile, tmp->datafield, SEEK_SET);
if (read(datafile,buff,tmp->size)<tmp->size)
{
printf("Failed to read entire data entry");
@@ -132,9 +132,9 @@ int read_msg(int folnum, int msgnum, struct user *user)
tmppos=lseek(headfile,0,2);
posn=(msgnum - data.last - 1)*sizeof(struct Header);
if (posn < -tmppos)
- lseek(headfile, 0, 0);
+ lseek(headfile, 0, SEEK_SET);
else
- lseek(headfile, posn, 1);
+ lseek(headfile, posn, SEEK_CUR);
while (get_data(headfile,&head) && head.Ref<msgnum);
if (head.Ref==msgnum)
{
@@ -288,9 +288,9 @@ int get_mesg_header(struct folder *data, int msgnum, struct Header *head)
/* locate to file data */
posn=(msgnum - data->last - 1)*sizeof(struct Header);
if (posn < -tmppos)
- lseek(headfile, 0, 0);
+ lseek(headfile, 0, SEEK_SET);
else
- lseek(headfile, posn, 1);
+ lseek(headfile, posn, SEEK_CUR);
/* read it */
while (get_data(headfile, head) && head->Ref < msgnum);
=====================================
src/folders.c
=====================================
--- a/src/folders.c
+++ b/src/folders.c
@@ -108,7 +108,7 @@ int get_folder_number(struct folder *fol, int num)
if (nofolders())
{printf("There are no folders !\n");return 0;}
if ((file=openfolderfile(O_RDONLY)) < 0) return 0;
- lseek(file,sizeof(*fol)*num,0);
+ lseek(file, sizeof(*fol) * num, SEEK_SET);
if (read(file,fol,sizeof(*fol))<0)
{
perror("get_folder_number");
View it on GitLab: https://projects.sucs.org/arthur/mw/commit/2b6a2c76e52ab6a7e6aa1c9f42e677b31b74f696
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/mw-devel/attachments/20151114/f89c2674/attachment-0001.html>
More information about the mw-devel
mailing list