`cat`/file.h: move `concatFileToStdout` func to file.h.

another thing i figure may be somewhat needed.
master
Drake 3 years ago
parent 42e3204429
commit 1567e63152

@ -1,4 +1,6 @@
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
/*
BSD 3-Clause License
@ -49,3 +51,18 @@ static _Bool isSymlink(const char *path) {
lstat(path, &path_stat);
return S_ISLNK(path_stat.st_mode);
}
static int concatFileToStdout(char *file) {
FILE *fp;
fp = fopen(file, "r");
if (fp == NULL) {
printf("failed to open '%s'. perhaps the path doesn't exist?\n", file);
exit(1);
}
char *contents = malloc(2);
while (fgets(contents, 2, fp) != NULL) {
printf("%s", contents);
}
free(contents);
return 0;
}

@ -4,6 +4,8 @@
#include <string.h>
#include <unistd.h>
#include "file.h"
/*
BSD 3-Clause License
@ -36,21 +38,6 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
int concatFileToStdout(char *file) {
FILE *fp;
fp = fopen(file, "r");
if (fp == NULL) {
printf("failed to open '%s'. perhaps the path doesn't exist?\n", file);
exit(1);
}
char *contents = malloc(LINE_MAX + 1);
while (fgets(contents, LINE_MAX + 1, fp) != NULL) {
printf("%s", contents);
}
free(contents);
return 0;
}
int main(int argc, char **argv) {
if (argc == 1) {
char ch;

Loading…
Cancel
Save