We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent bde354a commit 9a35397Copy full SHA for 9a35397
1 file changed
0x15-file_io/1-create_file.c
@@ -0,0 +1,31 @@
1
+#include "main.h"
2
+
3
+/**
4
+ * create_file - creates a file
5
+ * @filename: filename to grab
6
+ * @text_content: content to add
7
+ * Return: int value
8
+ */
9
+int create_file(const char *filename, char *text_content)
10
+{
11
+ int fd, len = 0;
12
+ long int wrote;
13
14
+ if (filename == NULL)
15
+ return (-1);
16
+ fd = open(filename, O_CREAT | O_RDWR | O_TRUNC, 0600);
17
+ if (fd == -1)
18
19
+ if (text_content != NULL)
20
+ {
21
22
+ while (text_content[len])
23
+ len++;
24
+ wrote = write(fd, text_content, len);
25
+ if (wrote == -1)
26
27
+ }
28
+ if (close(fd) == -1)
29
30
+ return (1);
31
+}
0 commit comments