summaryrefslogtreecommitdiff
path: root/sys/src/ape/lib/ap/plan9/rename.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2019-06-23 22:35:14 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2019-06-23 22:35:14 +0200
commit7d3cc1c55a435bd9e3d37d9bf8a9299ea9e1f87e (patch)
tree5b04dfddffce6348658ac592262b604a70dc3991 /sys/src/ape/lib/ap/plan9/rename.c
parentd4bc9052beb3305d64a353a16641740380eb87af (diff)
ape: revert rename() change
new implementation gets stuck in a infinite loop. backing this out for now.
Diffstat (limited to 'sys/src/ape/lib/ap/plan9/rename.c')
-rw-r--r--sys/src/ape/lib/ap/plan9/rename.c52
1 files changed, 26 insertions, 26 deletions
diff --git a/sys/src/ape/lib/ap/plan9/rename.c b/sys/src/ape/lib/ap/plan9/rename.c
index c02948316..182f49ce2 100644
--- a/sys/src/ape/lib/ap/plan9/rename.c
+++ b/sys/src/ape/lib/ap/plan9/rename.c
@@ -10,7 +10,7 @@
int
rename(const char *from, const char *to)
{
- int n, ffd, tfd;
+ int n, i;
char *f, *t;
Dir *d, nd;
@@ -31,45 +31,45 @@ rename(const char *from, const char *to)
}
f = strrchr(from, '/');
t = strrchr(to, '/');
- f = f? f+1 : (char*)from;
- t = t? t+1 : (char*)to;
+ f = f? f+1 : from;
+ t = t? t+1 : to;
+ n = 0;
if(f-from==t-to && strncmp(from, to, f-from)==0){
/* from and to are in same directory (we miss some cases) */
+ i = strlen(t);
_nulldir(&nd);
nd.name = t;
if(_dirwstat(from, &nd) < 0){
_syserrno();
- return -1;
+ n = -1;
}
}else{
/* different directories: have to copy */
+ int ffd, tfd;
char buf[8192];
-
- if((ffd = _OPEN(from, OREAD)) == -1)
- goto err1;
- if((tfd = _CREATE(to, OWRITE, d->mode)) == -1)
- goto err2;
- n = 0;
- while(n>=0){
- if((n = _READ(ffd, buf, sizeof(buf))) == -1)
- goto err2;
- if(_WRITE(tfd, buf, n) != n)
- goto err2;
+ if((ffd = _OPEN(from, OREAD)) < 0 ||
+ (tfd = _CREATE(to, OWRITE, d->mode)) < 0){
+ _CLOSE(ffd);
+ _syserrno();
+ n = -1;
}
+ while(n>=0 && (n = _READ(ffd, buf, sizeof(buf))) > 0)
+ if(_WRITE(tfd, buf, n) != n){
+ _syserrno();
+ n = -1;
+ }
_CLOSE(ffd);
_CLOSE(tfd);
- if(_REMOVE(from) < 0)
- goto err2;
+ if(n>0)
+ n = 0;
+ if(n == 0) {
+ if(_REMOVE(from) < 0){
+ _syserrno();
+ return -1;
+ }
+ }
}
free(d);
- return 0;
-
-err2:
- _CLOSE(tfd);
-err1:
- _CLOSE(ffd);
- _syserrno();
- free(d);
- return -1;
+ return n;
}