Deleted Added
full compact
fetch.c (186124) fetch.c (186241)
1/*-
2 * Copyright (c) 2000-2004 Dag-Erling Co��dan Sm��rgrav
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2000-2004 Dag-Erling Co��dan Sm��rgrav
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: head/usr.bin/fetch/fetch.c 186124 2008-12-15 08:27:44Z murray $");
30__FBSDID("$FreeBSD: head/usr.bin/fetch/fetch.c 186241 2008-12-17 18:00:18Z murray $");
31
32#include <sys/param.h>
33#include <sys/socket.h>
34#include <sys/stat.h>
35#include <sys/time.h>
36
37#include <ctype.h>
38#include <err.h>
39#include <errno.h>
40#include <signal.h>
41#include <stdint.h>
42#include <stdio.h>
43#include <stdlib.h>
44#include <string.h>
31
32#include <sys/param.h>
33#include <sys/socket.h>
34#include <sys/stat.h>
35#include <sys/time.h>
36
37#include <ctype.h>
38#include <err.h>
39#include <errno.h>
40#include <signal.h>
41#include <stdint.h>
42#include <stdio.h>
43#include <stdlib.h>
44#include <string.h>
45#include <sysexits.h>
46#include <termios.h>
47#include <unistd.h>
48
49#include <fetch.h>
50
51#define MINBUFSIZE 4096
52
53/* Option flags */

--- 806 unchanged lines hidden (view full) ---

860 case 'w':
861 a_flag = 1;
862 w_secs = strtol(optarg, &end, 10);
863 if (*optarg == '\0' || *end != '\0')
864 errx(1, "invalid delay (%s)", optarg);
865 break;
866 default:
867 usage();
45#include <termios.h>
46#include <unistd.h>
47
48#include <fetch.h>
49
50#define MINBUFSIZE 4096
51
52/* Option flags */

--- 806 unchanged lines hidden (view full) ---

859 case 'w':
860 a_flag = 1;
861 w_secs = strtol(optarg, &end, 10);
862 if (*optarg == '\0' || *end != '\0')
863 errx(1, "invalid delay (%s)", optarg);
864 break;
865 default:
866 usage();
868 exit(EX_USAGE);
867 exit(1);
869 }
870
871 argc -= optind;
872 argv += optind;
873
874 if (h_hostname || f_filename || c_dirname) {
875 if (!h_hostname || !f_filename || argc) {
876 usage();
868 }
869
870 argc -= optind;
871 argv += optind;
872
873 if (h_hostname || f_filename || c_dirname) {
874 if (!h_hostname || !f_filename || argc) {
875 usage();
877 exit(EX_USAGE);
876 exit(1);
878 }
879 /* XXX this is a hack. */
880 if (strcspn(h_hostname, "@:/") != strlen(h_hostname))
881 errx(1, "invalid hostname");
882 if (asprintf(argv, "ftp://%s/%s/%s", h_hostname,
883 c_dirname ? c_dirname : "", f_filename) == -1)
884 errx(1, "%s", strerror(ENOMEM));
885 argc++;
886 }
887
888 if (!argc) {
889 usage();
877 }
878 /* XXX this is a hack. */
879 if (strcspn(h_hostname, "@:/") != strlen(h_hostname))
880 errx(1, "invalid hostname");
881 if (asprintf(argv, "ftp://%s/%s/%s", h_hostname,
882 c_dirname ? c_dirname : "", f_filename) == -1)
883 errx(1, "%s", strerror(ENOMEM));
884 argc++;
885 }
886
887 if (!argc) {
888 usage();
890 exit(EX_USAGE);
889 exit(1);
891 }
892
893 /* allocate buffer */
894 if (B_size < MINBUFSIZE)
895 B_size = MINBUFSIZE;
896 if ((buf = malloc(B_size)) == NULL)
897 errx(1, "%s", strerror(ENOMEM));
898

--- 24 unchanged lines hidden (view full) ---

923
924 /* output file */
925 if (o_flag) {
926 if (strcmp(o_filename, "-") == 0) {
927 o_stdout = 1;
928 } else if (stat(o_filename, &sb) == -1) {
929 if (errno == ENOENT) {
930 if (argc > 1)
890 }
891
892 /* allocate buffer */
893 if (B_size < MINBUFSIZE)
894 B_size = MINBUFSIZE;
895 if ((buf = malloc(B_size)) == NULL)
896 errx(1, "%s", strerror(ENOMEM));
897

--- 24 unchanged lines hidden (view full) ---

922
923 /* output file */
924 if (o_flag) {
925 if (strcmp(o_filename, "-") == 0) {
926 o_stdout = 1;
927 } else if (stat(o_filename, &sb) == -1) {
928 if (errno == ENOENT) {
929 if (argc > 1)
931 errx(EX_USAGE, "%s is not a directory",
930 errx(1, "%s is not a directory",
932 o_filename);
933 } else {
931 o_filename);
932 } else {
934 err(EX_IOERR, "%s", o_filename);
933 err(1, "%s", o_filename);
935 }
936 } else {
937 if (sb.st_mode & S_IFDIR)
938 o_directory = 1;
939 }
940 }
941
942 /* check if output is to a tty (for progress report) */

--- 66 unchanged lines hidden ---
934 }
935 } else {
936 if (sb.st_mode & S_IFDIR)
937 o_directory = 1;
938 }
939 }
940
941 /* check if output is to a tty (for progress report) */

--- 66 unchanged lines hidden ---