file.c (a8b3e6f10f08f66ae1072efd087b30966a3654f6) | file.c (b4fd310e163477236a241580b3b8c29aee65f4cc) |
---|---|
1/* 2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) 3 * Licensed under the GPL 4 */ 5 6#include <stdio.h> 7#include <unistd.h> 8#include <errno.h> --- 105 unchanged lines hidden (view full) --- 114 *rows = size.ws_row; 115 *cols = size.ws_col; 116 117 return(0); 118} 119 120int os_new_tty_pgrp(int fd, int pid) 121{ | 1/* 2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) 3 * Licensed under the GPL 4 */ 5 6#include <stdio.h> 7#include <unistd.h> 8#include <errno.h> --- 105 unchanged lines hidden (view full) --- 114 *rows = size.ws_row; 115 *cols = size.ws_col; 116 117 return(0); 118} 119 120int os_new_tty_pgrp(int fd, int pid) 121{ |
122 if(ioctl(fd, TIOCSCTTY, 0) < 0){ 123 printk("TIOCSCTTY failed, errno = %d\n", errno); 124 return(-errno); 125 } | 122 if(ioctl(fd, TIOCSCTTY, 0) < 0) 123 return -errno; |
126 | 124 |
127 if(tcsetpgrp(fd, pid) < 0){ 128 printk("tcsetpgrp failed, errno = %d\n", errno); 129 return(-errno); 130 } | 125 if(tcsetpgrp(fd, pid) < 0) 126 return -errno; |
131 132 return(0); 133} 134 135/* FIXME: ensure namebuf in os_get_if_name is big enough */ 136int os_get_ifname(int fd, char* namebuf) 137{ 138 if(ioctl(fd, SIOCGIFNAME, namebuf) < 0) 139 return(-errno); 140 141 return(0); 142} 143 144int os_set_slip(int fd) 145{ 146 int disc, sencap; 147 148 disc = N_SLIP; | 127 128 return(0); 129} 130 131/* FIXME: ensure namebuf in os_get_if_name is big enough */ 132int os_get_ifname(int fd, char* namebuf) 133{ 134 if(ioctl(fd, SIOCGIFNAME, namebuf) < 0) 135 return(-errno); 136 137 return(0); 138} 139 140int os_set_slip(int fd) 141{ 142 int disc, sencap; 143 144 disc = N_SLIP; |
149 if(ioctl(fd, TIOCSETD, &disc) < 0){ 150 printk("Failed to set slip line discipline - " 151 "errno = %d\n", errno); 152 return(-errno); 153 } | 145 if(ioctl(fd, TIOCSETD, &disc) < 0) 146 return -errno; |
154 155 sencap = 0; | 147 148 sencap = 0; |
156 if(ioctl(fd, SIOCSIFENCAP, &sencap) < 0){ 157 printk("Failed to set slip encapsulation - " 158 "errno = %d\n", errno); 159 return(-errno); 160 } | 149 if(ioctl(fd, SIOCSIFENCAP, &sencap) < 0) 150 return -errno; |
161 162 return(0); 163} 164 165int os_set_owner(int fd, int pid) 166{ 167 if(fcntl(fd, F_SETOWN, pid) < 0){ 168 int save_errno = errno; --- 6 unchanged lines hidden (view full) --- 175} 176 177/* FIXME? moved wholesale from sigio_user.c to get fcntls out of that file */ 178int os_sigio_async(int master, int slave) 179{ 180 int flags; 181 182 flags = fcntl(master, F_GETFL); | 151 152 return(0); 153} 154 155int os_set_owner(int fd, int pid) 156{ 157 if(fcntl(fd, F_SETOWN, pid) < 0){ 158 int save_errno = errno; --- 6 unchanged lines hidden (view full) --- 165} 166 167/* FIXME? moved wholesale from sigio_user.c to get fcntls out of that file */ 168int os_sigio_async(int master, int slave) 169{ 170 int flags; 171 172 flags = fcntl(master, F_GETFL); |
183 if(flags < 0) { 184 printk("fcntl F_GETFL failed, errno = %d\n", errno); 185 return(-errno); 186 } | 173 if(flags < 0) 174 return errno; |
187 188 if((fcntl(master, F_SETFL, flags | O_NONBLOCK | O_ASYNC) < 0) || | 175 176 if((fcntl(master, F_SETFL, flags | O_NONBLOCK | O_ASYNC) < 0) || |
189 (fcntl(master, F_SETOWN, os_getpid()) < 0)){ 190 printk("fcntl F_SETFL or F_SETOWN failed, errno = %d\n", 191 errno); 192 return(-errno); 193 } | 177 (fcntl(master, F_SETOWN, os_getpid()) < 0)) 178 return -errno; |
194 | 179 |
195 if((fcntl(slave, F_SETFL, flags | O_NONBLOCK) < 0)){ 196 printk("fcntl F_SETFL failed, errno = %d\n", errno); 197 return(-errno); 198 } | 180 if((fcntl(slave, F_SETFL, flags | O_NONBLOCK) < 0)) 181 return -errno; |
199 200 return(0); 201} 202 203int os_mode_fd(int fd, int mode) 204{ 205 int err; 206 --- 43 unchanged lines hidden (view full) --- 250 251 *mode_out = of_read(*mode_out); 252 253 return(0); 254} 255 256int os_open_file(char *file, struct openflags flags, int mode) 257{ | 182 183 return(0); 184} 185 186int os_mode_fd(int fd, int mode) 187{ 188 int err; 189 --- 43 unchanged lines hidden (view full) --- 233 234 *mode_out = of_read(*mode_out); 235 236 return(0); 237} 238 239int os_open_file(char *file, struct openflags flags, int mode) 240{ |
258 int fd, f = 0; | 241 int fd, err, f = 0; |
259 260 if(flags.r && flags.w) f = O_RDWR; 261 else if(flags.r) f = O_RDONLY; 262 else if(flags.w) f = O_WRONLY; 263 else f = 0; 264 265 if(flags.s) f |= O_SYNC; 266 if(flags.c) f |= O_CREAT; 267 if(flags.t) f |= O_TRUNC; 268 if(flags.e) f |= O_EXCL; 269 270 fd = open64(file, f, mode); 271 if(fd < 0) 272 return(-errno); 273 274 if(flags.cl && fcntl(fd, F_SETFD, 1)){ | 242 243 if(flags.r && flags.w) f = O_RDWR; 244 else if(flags.r) f = O_RDONLY; 245 else if(flags.w) f = O_WRONLY; 246 else f = 0; 247 248 if(flags.s) f |= O_SYNC; 249 if(flags.c) f |= O_CREAT; 250 if(flags.t) f |= O_TRUNC; 251 if(flags.e) f |= O_EXCL; 252 253 fd = open64(file, f, mode); 254 if(fd < 0) 255 return(-errno); 256 257 if(flags.cl && fcntl(fd, F_SETFD, 1)){ |
258 err = -errno; |
|
275 os_close_file(fd); | 259 os_close_file(fd); |
276 return(-errno); | 260 return err; |
277 } 278 279 return(fd); 280} 281 282int os_connect_socket(char *name) 283{ 284 struct sockaddr_un sock; --- 93 unchanged lines hidden (view full) --- 378 int fd, blocks; 379 380 fd = os_open_file(file, of_read(OPENFLAGS()), 0); 381 if(fd < 0){ 382 printk("Couldn't open \"%s\", errno = %d\n", file, -fd); 383 return(fd); 384 } 385 if(ioctl(fd, BLKGETSIZE, &blocks) < 0){ | 261 } 262 263 return(fd); 264} 265 266int os_connect_socket(char *name) 267{ 268 struct sockaddr_un sock; --- 93 unchanged lines hidden (view full) --- 362 int fd, blocks; 363 364 fd = os_open_file(file, of_read(OPENFLAGS()), 0); 365 if(fd < 0){ 366 printk("Couldn't open \"%s\", errno = %d\n", file, -fd); 367 return(fd); 368 } 369 if(ioctl(fd, BLKGETSIZE, &blocks) < 0){ |
370 err = -errno; |
|
386 printk("Couldn't get the block size of \"%s\", " 387 "errno = %d\n", file, errno); | 371 printk("Couldn't get the block size of \"%s\", " 372 "errno = %d\n", file, errno); |
388 err = -errno; | |
389 os_close_file(fd); 390 return(err); 391 } 392 *size_out = ((long long) blocks) * 512; 393 os_close_file(fd); 394 return(0); 395 } 396 *size_out = buf.ust_size; --- 71 unchanged lines hidden (view full) --- 468 printk("os_pipe : Setting FD_CLOEXEC failed, err = %d\n", -err); 469 os_close_file(fds[1]); 470 os_close_file(fds[0]); 471 return(err); 472} 473 474int os_set_fd_async(int fd, int owner) 475{ | 373 os_close_file(fd); 374 return(err); 375 } 376 *size_out = ((long long) blocks) * 512; 377 os_close_file(fd); 378 return(0); 379 } 380 *size_out = buf.ust_size; --- 71 unchanged lines hidden (view full) --- 452 printk("os_pipe : Setting FD_CLOEXEC failed, err = %d\n", -err); 453 os_close_file(fds[1]); 454 os_close_file(fds[0]); 455 return(err); 456} 457 458int os_set_fd_async(int fd, int owner) 459{ |
460 int err; 461 |
|
476 /* XXX This should do F_GETFL first */ 477 if(fcntl(fd, F_SETFL, O_ASYNC | O_NONBLOCK) < 0){ | 462 /* XXX This should do F_GETFL first */ 463 if(fcntl(fd, F_SETFL, O_ASYNC | O_NONBLOCK) < 0){ |
464 err = -errno; |
|
478 printk("os_set_fd_async : failed to set O_ASYNC and " 479 "O_NONBLOCK on fd # %d, errno = %d\n", fd, errno); | 465 printk("os_set_fd_async : failed to set O_ASYNC and " 466 "O_NONBLOCK on fd # %d, errno = %d\n", fd, errno); |
480 return(-errno); | 467 return err; |
481 } 482#ifdef notdef 483 if(fcntl(fd, F_SETFD, 1) < 0){ 484 printk("os_set_fd_async : Setting FD_CLOEXEC failed, " 485 "errno = %d\n", errno); 486 } 487#endif 488 489 if((fcntl(fd, F_SETSIG, SIGIO) < 0) || 490 (fcntl(fd, F_SETOWN, owner) < 0)){ | 468 } 469#ifdef notdef 470 if(fcntl(fd, F_SETFD, 1) < 0){ 471 printk("os_set_fd_async : Setting FD_CLOEXEC failed, " 472 "errno = %d\n", errno); 473 } 474#endif 475 476 if((fcntl(fd, F_SETSIG, SIGIO) < 0) || 477 (fcntl(fd, F_SETOWN, owner) < 0)){ |
478 err = -errno; |
|
491 printk("os_set_fd_async : Failed to fcntl F_SETOWN " 492 "(or F_SETSIG) fd %d to pid %d, errno = %d\n", fd, 493 owner, errno); | 479 printk("os_set_fd_async : Failed to fcntl F_SETOWN " 480 "(or F_SETSIG) fd %d to pid %d, errno = %d\n", fd, 481 owner, errno); |
494 return(-errno); | 482 return err; |
495 } 496 497 return(0); 498} 499 500int os_clear_fd_async(int fd) 501{ 502 int flags = fcntl(fd, F_GETFL); --- 8 unchanged lines hidden (view full) --- 511{ 512 int flags; 513 514 flags = fcntl(fd, F_GETFL); 515 516 if(blocking) flags &= ~O_NONBLOCK; 517 else flags |= O_NONBLOCK; 518 | 483 } 484 485 return(0); 486} 487 488int os_clear_fd_async(int fd) 489{ 490 int flags = fcntl(fd, F_GETFL); --- 8 unchanged lines hidden (view full) --- 499{ 500 int flags; 501 502 flags = fcntl(fd, F_GETFL); 503 504 if(blocking) flags &= ~O_NONBLOCK; 505 else flags |= O_NONBLOCK; 506 |
519 if(fcntl(fd, F_SETFL, flags) < 0){ 520 printk("Failed to change blocking on fd # %d, errno = %d\n", 521 fd, errno); 522 return(-errno); 523 } | 507 if(fcntl(fd, F_SETFL, flags) < 0) 508 return -errno; 509 |
524 return(0); 525} 526 527int os_accept_connection(int fd) 528{ 529 int new; 530 531 new = accept(fd, NULL, 0); --- 72 unchanged lines hidden (view full) --- 604} 605 606int os_create_unix_socket(char *file, int len, int close_on_exec) 607{ 608 struct sockaddr_un addr; 609 int sock, err; 610 611 sock = socket(PF_UNIX, SOCK_DGRAM, 0); | 510 return(0); 511} 512 513int os_accept_connection(int fd) 514{ 515 int new; 516 517 new = accept(fd, NULL, 0); --- 72 unchanged lines hidden (view full) --- 590} 591 592int os_create_unix_socket(char *file, int len, int close_on_exec) 593{ 594 struct sockaddr_un addr; 595 int sock, err; 596 597 sock = socket(PF_UNIX, SOCK_DGRAM, 0); |
612 if (sock < 0){ 613 printk("create_unix_socket - socket failed, errno = %d\n", 614 errno); 615 return(-errno); 616 } | 598 if(sock < 0) 599 return -errno; |
617 618 if(close_on_exec) { 619 err = os_set_exec_close(sock, 1); 620 if(err < 0) 621 printk("create_unix_socket : close_on_exec failed, " 622 "err = %d", -err); 623 } 624 625 addr.sun_family = AF_UNIX; 626 627 /* XXX Be more careful about overflow */ 628 snprintf(addr.sun_path, len, "%s", file); 629 630 err = bind(sock, (struct sockaddr *) &addr, sizeof(addr)); | 600 601 if(close_on_exec) { 602 err = os_set_exec_close(sock, 1); 603 if(err < 0) 604 printk("create_unix_socket : close_on_exec failed, " 605 "err = %d", -err); 606 } 607 608 addr.sun_family = AF_UNIX; 609 610 /* XXX Be more careful about overflow */ 611 snprintf(addr.sun_path, len, "%s", file); 612 613 err = bind(sock, (struct sockaddr *) &addr, sizeof(addr)); |
631 if (err < 0){ 632 printk("create_listening_socket at '%s' - bind failed, " 633 "errno = %d\n", file, errno); 634 return(-errno); 635 } | 614 if(err < 0) 615 return -errno; |
636 637 return(sock); 638} 639 640void os_flush_stdout(void) 641{ 642 fflush(stdout); 643} --- 37 unchanged lines hidden --- | 616 617 return(sock); 618} 619 620void os_flush_stdout(void) 621{ 622 fflush(stdout); 623} --- 37 unchanged lines hidden --- |