readmmap.c (2fae26bd8b752cfae083962a152f4b1ee54ada17) | readmmap.c (f27fb06cadc6a8e75ebebd3b60c8a9dc9ae1b833) |
---|---|
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 69 unchanged lines hidden (view full) --- 78 if (fd == -1) { 79 perror("open to create"); 80 retval = 1; 81 goto end; 82 } 83 84 bytes = write(fd, buf, size); 85 if (bytes != size) { | 1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 69 unchanged lines hidden (view full) --- 78 if (fd == -1) { 79 perror("open to create"); 80 retval = 1; 81 goto end; 82 } 83 84 bytes = write(fd, buf, size); 85 if (bytes != size) { |
86 (void) printf("short write: %d != %ud\n", bytes, size); | 86 (void) printf("short write: %d != %zu\n", bytes, size); |
87 retval = 1; 88 goto end; 89 } 90 91 map = mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); 92 if (map == MAP_FAILED) { 93 perror("mmap"); 94 retval = 1; --- 14 unchanged lines hidden (view full) --- 109 if (munmap(map, size) != 0) { 110 perror("munmap"); 111 retval = 1; 112 goto end; 113 } 114 115 bytes = pread(fd, buf, size, 0); 116 if (bytes != size) { | 87 retval = 1; 88 goto end; 89 } 90 91 map = mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); 92 if (map == MAP_FAILED) { 93 perror("mmap"); 94 retval = 1; --- 14 unchanged lines hidden (view full) --- 109 if (munmap(map, size) != 0) { 110 perror("munmap"); 111 retval = 1; 112 goto end; 113 } 114 115 bytes = pread(fd, buf, size, 0); 116 if (bytes != size) { |
117 (void) printf("short read: %d != %ud\n", bytes, size); | 117 (void) printf("short read: %d != %zu\n", bytes, size); |
118 retval = 1; 119 goto end; 120 } 121 122 if (buf[idx] != 1) { 123 (void) printf( | 118 retval = 1; 119 goto end; 120 } 121 122 if (buf[idx] != 1) { 123 (void) printf( |
124 "bad data from read! got buf[%ud]=%d, expected 1\n", | 124 "bad data from read! got buf[%zu]=%d, expected 1\n", |
125 idx, buf[idx]); 126 retval = 1; 127 goto end; 128 } 129 | 125 idx, buf[idx]); 126 retval = 1; 127 goto end; 128 } 129 |
130 (void) printf("good data from read: buf[%ud]=1\n", idx); | 130 (void) printf("good data from read: buf[%zu]=1\n", idx); |
131end: 132 if (fd != -1) { 133 (void) close(fd); 134 } 135 if (buf != NULL) { 136 free(buf); 137 } 138 139 return (retval); 140} | 131end: 132 if (fd != -1) { 133 (void) close(fd); 134 } 135 if (buf != NULL) { 136 free(buf); 137 } 138 139 return (retval); 140} |