ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/BeOS/extfs_beos.cpp
(Generate patch)

Comparing BasiliskII/src/BeOS/extfs_beos.cpp (file contents):
Revision 1.2 by cebix, 1999-10-19T21:33:57Z vs.
Revision 1.10 by cebix, 2000-04-10T18:52:49Z

# Line 1 | Line 1
1   /*
2   *  extfs_beos.cpp - MacOS file system for access native file system access, BeOS specific stuff
3   *
4 < *  Basilisk II (C) 1997-1999 Christian Bauer
4 > *  Basilisk II (C) 1997-2000 Christian Bauer
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 72 | Line 72 | void extfs_exit(void)
72  
73  
74   /*
75 + *  Add component to path name
76 + */
77 +
78 + void add_path_component(char *path, const char *component)
79 + {
80 +        int l = strlen(path);
81 +        if (l < MAX_PATH_LENGTH-1 && path[l-1] != '/') {
82 +                path[l] = '/';
83 +                path[l+1] = 0;
84 +        }
85 +        strncat(path, component, MAX_PATH_LENGTH-1);
86 + }
87 +
88 +
89 + /*
90   *  Get/set finder type/creator for file specified by full path
91   */
92  
# Line 268 | Line 283 | int open_rfork(const char *path, int fla
283          // Open temporary file for resource fork
284          char rname[L_tmpnam];
285          tmpnam(rname);
286 <        int rfd = open(rname, O_RDWR | O_CREAT | O_TRUNC, 0664);
286 >        int rfd = open(rname, O_RDWR | O_CREAT | O_TRUNC, 0666);
287          if (rfd < 0) {
288                  close(fd);
289                  return -1;
# Line 354 | Line 369 | void close_rfork(const char *path, int f
369  
370   /*
371   *  Read "length" bytes from file to "buffer",
372 < *  returns number of bytes read (or 0)
372 > *  returns number of bytes read (or -1 on error)
373   */
374  
375   static inline ssize_t sread(int fd, void *buf, size_t count)
# Line 364 | Line 379 | static inline ssize_t sread(int fd, void
379          return res;
380   }
381  
382 < size_t extfs_read(int fd, void *buffer, size_t length)
382 > ssize_t extfs_read(int fd, void *buffer, size_t length)
383   {
369        errno = 0;
370
384          // Buffer in kernel space?
372        size_t actual = 0;
385          if ((uint32)buffer < 0x80000000) {
386  
387                  // Yes, transfer via buffer
388 +                ssize_t actual = 0;
389                  while (length) {
390                          size_t transfer_size = (length > TMP_BUF_SIZE) ? TMP_BUF_SIZE : length;
391                          ssize_t res = sread(fd, tmp_buf, transfer_size);
392 <                        if (res >= 0) {
393 <                                memcpy(buffer, tmp_buf, res);
394 <                                buffer = (void *)((uint8 *)buffer + res);
395 <                                length -= res;
396 <                                actual += res;
397 <                        }
392 >                        if (res < 0)
393 >                                return res;
394 >                        memcpy(buffer, tmp_buf, res);
395 >                        buffer = (void *)((uint8 *)buffer + res);
396 >                        length -= res;
397 >                        actual += res;
398                          if (res != transfer_size)
399                                  return actual;
400                  }
401 +                return actual;
402  
403          } else {
404  
405                  // No, transfer directly
406 <                actual = sread(fd, buffer, length);
393 <                if (actual < 0)
394 <                        actual = 0;
406 >                return sread(fd, buffer, length);
407          }
396        return actual;
408   }
409  
410  
411   /*
412   *  Write "length" bytes from "buffer" to file,
413 < *  returns number of bytes written (or 0)
413 > *  returns number of bytes written (or -1 on error)
414   */
415  
416   static inline ssize_t swrite(int fd, void *buf, size_t count)
# Line 409 | Line 420 | static inline ssize_t swrite(int fd, voi
420          return res;
421   }
422  
423 < size_t extfs_write(int fd, void *buffer, size_t length)
423 > ssize_t extfs_write(int fd, void *buffer, size_t length)
424   {
414        errno = 0;
415
425          // Buffer in kernel space?
417        size_t actual = 0;
426          if ((uint32)buffer < 0x80000000) {
427  
428                  // Yes, transfer via buffer
429 +                ssize_t actual = 0;
430                  while (length) {
431                          size_t transfer_size = (length > TMP_BUF_SIZE) ? TMP_BUF_SIZE : length;
432                          memcpy(tmp_buf, buffer, transfer_size);
433                          ssize_t res = swrite(fd, tmp_buf, transfer_size);
434 <                        if (res >= 0) {
435 <                                buffer = (void *)((uint8 *)buffer + res);
436 <                                length -= res;
437 <                                actual += res;
438 <                        }
434 >                        if (res < 0)
435 >                                return res;
436 >                        buffer = (void *)((uint8 *)buffer + res);
437 >                        length -= res;
438 >                        actual += res;
439                          if (res != transfer_size)
440                                  return actual;
441                  }
442 +                return actual;
443  
444          } else {
445  
446                  // No, transfer directly
447 <                actual = swrite(fd, buffer, length);
438 <                if (actual < 0)
439 <                        actual = 0;
447 >                return swrite(fd, buffer, length);
448          }
449 <        return actual;
449 > }
450 >
451 >
452 > /*
453 > *  Remove file/directory, returns false on error (and sets errno)
454 > */
455 >
456 > bool extfs_remove(const char *path)
457 > {
458 >        if (remove(path) < 0) {
459 >                if (errno == EISDIR)
460 >                        return rmdir(path) == 0;
461 >                else
462 >                        return false;
463 >        }
464 >        return true;
465 > }
466 >
467 >
468 > /*
469 > *  Rename/move file/directory, returns false on error (and sets errno)
470 > */
471 >
472 > bool extfs_rename(const char *old_path, const char *new_path)
473 > {
474 >        return rename(old_path, new_path) == 0;
475   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines