Lines Matching refs:ar
32 Ardir_t* ar;
38 if (!(ar = newof(0, Ardir_t, 1, strlen(file) + 1)))
40 strcpy(ar->path = (char*)(ar + 1), file);
41 ar->flags = flags;
42 if (((ar->fd = open(file, (flags & ARDIR_CREATE) ? (O_CREAT|O_TRUNC|O_RDWR|O_BINARY|O_cloexec) : (flags & ARDIR_UPDATE) ? (O_RDWR|O_BINARY|O_cloexec) : (O_RDONLY|O_BINARY|O_cloexec))) < 0 || fstat(ar->fd, &ar->st) || !S_ISREG(ar->st.st_mode)) && (!meth || !(flags & ARDIR_FORCE)))
44 ardirclose(ar);
47 if (ar->fd >= 0 && ((pos = lseek(ar->fd, (off_t)0, SEEK_CUR)) < 0 || (n = read(ar->fd, buf, sizeof(buf))) < 0 || lseek(ar->fd, pos, SEEK_SET) != pos))
49 ardirclose(ar);
52 if (!(ar->meth = meth))
55 for (meth = ar_first_method; ar->meth = meth; meth = meth->next)
56 if ((!skip || !strmatch(meth->name, skip)) && !(*meth->openf)(ar, buf, n))
58 if (!(ar->meth = meth))
60 ardirclose(ar);
64 else if ((*meth->openf)(ar, buf, n))
66 ardirclose(ar);
69 return ar;
73 ardirnext(Ardir_t* ar)
75 return (ar->meth && ar->meth->nextf) ? (*ar->meth->nextf)(ar) : (Ardirent_t*)0;
79 ardircopy(Ardir_t* ar, Ardirent_t* ent, int fd)
89 ar->error = ENOSYS;
92 pos = lseek(ar->fd, (off_t)0, SEEK_CUR);
93 if (lseek(ar->fd, ent->offset, SEEK_SET) != ent->offset)
99 if ((n = read(ar->fd, buf, m)) < 0)
101 ar->error = errno;
108 ar->error = errno;
113 lseek(ar->fd, pos, SEEK_SET);
125 ardirchange(Ardir_t* ar, Ardirent_t* ent)
127 if (!ar->meth || !ar->meth->changef)
129 ar->error = EINVAL;
132 return (*ar->meth->changef)(ar, ent);
136 ardirinsert(Ardir_t* ar, const char* name, int flags)
138 if (!ar->meth || !ar->meth->insertf)
140 ar->error = EINVAL;
143 return (*ar->meth->insertf)(ar, name, flags);
147 ardirspecial(Ardir_t* ar)
149 if (!ar->meth || !ar->meth->specialf)
151 ar->error = EINVAL;
154 return (*ar->meth->specialf)(ar);
158 ardirclose(Ardir_t* ar)
162 if (!ar)
164 r = (ar->meth && ar->meth->closef) ? (*ar->meth->closef)(ar) : -1;
165 if (ar->error)
167 if (ar->fd >= 0)
168 close(ar->fd);
169 free(ar);