Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F146761377
D28958.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D28958.diff
View Options
Index: bin/cp/utils.c
===================================================================
--- bin/cp/utils.c
+++ bin/cp/utils.c
@@ -75,11 +75,29 @@
#define BUFSIZE_SMALL (MAXPHYS)
static ssize_t
-copy_fallback(int from_fd, int to_fd, char *buf, size_t bufsize)
+copy_fallback(int from_fd, int to_fd)
{
+ static char *buf = NULL;
+ static size_t bufsize;
+
ssize_t rcount, wresid, wcount = 0;
char *bufp;
+ if (!buf) {
+ /*
+ * Note that buf and bufsize are static. If
+ * malloc() fails, it will fail at the start
+ * and not copy only some files.
+ */
+ if (sysconf(_SC_PHYS_PAGES) > PHYSPAGES_THRESHOLD)
+ bufsize = MIN(BUFSIZE_MAX, MAXPHYS * 8);
+ else
+ bufsize = BUFSIZE_SMALL;
+ buf = malloc(bufsize);
+ if (!buf)
+ err(1, "Not enough memory");
+ }
+
rcount = read(from_fd, buf, bufsize);
if (rcount <= 0)
return (rcount);
@@ -96,8 +114,6 @@
int
copy_file(const FTSENT *entp, int dne)
{
- static char *buf = NULL;
- static size_t bufsize;
struct stat *fs;
ssize_t rcount, wcount;
size_t wresid;
@@ -216,21 +232,6 @@
} else
#endif
{
- if (buf == NULL) {
- /*
- * Note that buf and bufsize are static. If
- * malloc() fails, it will fail at the start
- * and not copy only some files.
- */
- if (sysconf(_SC_PHYS_PAGES) >
- PHYSPAGES_THRESHOLD)
- bufsize = MIN(BUFSIZE_MAX, MAXPHYS * 8);
- else
- bufsize = BUFSIZE_SMALL;
- buf = malloc(bufsize);
- if (buf == NULL)
- err(1, "Not enough memory");
- }
wtotal = 0;
do {
if (use_copy_file_range) {
@@ -241,10 +242,8 @@
use_copy_file_range = 0;
}
}
- if (!use_copy_file_range) {
- rcount = copy_fallback(from_fd, to_fd,
- buf, bufsize);
- }
+ if (!use_copy_file_range)
+ rcount = copy_fallback(from_fd, to_fd);
wtotal += rcount;
if (info) {
info = 0;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Mar 6, 9:19 AM (3 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29320942
Default Alt Text
D28958.diff (1 KB)
Attached To
Mode
D28958: cp: make buffer local to copy_fallback()
Attached
Detach File
Event Timeline
Log In to Comment