Skip to content

Commit 7e4facb

Browse files
author
Mohamed El mouhib
committed
added
1 parent 6795875 commit 7e4facb

11 files changed

+48
-8
lines changed

a.out

16.6 KB
Binary file not shown.

conversions.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: mel-mouh <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/11/18 23:07:50 by mel-mouh #+# #+# */
9-
/* Updated: 2024/11/19 22:39:42 by mel-mouh ### ########.fr */
9+
/* Updated: 2024/11/20 12:20:52 by mel-mouh ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

errors.log

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Testing output with closed stdout

ft_printf.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: mel-mouh <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/11/16 20:30:02 by mel-mouh #+# #+# */
9-
/* Updated: 2024/11/19 22:41:11 by mel-mouh ### ########.fr */
9+
/* Updated: 2024/11/20 12:30:35 by mel-mouh ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -18,7 +18,7 @@ int ft_printf(const char *str, ...)
1818
int count;
1919
va_list args;
2020

21-
if (str == NULL)
21+
if (str == NULL || write(1, 0, 0) == -1)
2222
return (-1);
2323
va_start(args, str);
2424
i = 0;

ft_putaddres.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: mel-mouh <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/11/18 19:32:03 by mel-mouh #+# #+# */
9-
/* Updated: 2024/11/19 22:00:54 by mel-mouh ### ########.fr */
9+
/* Updated: 2024/11/20 12:22:02 by mel-mouh ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

ft_putchar.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: mel-mouh <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/11/18 23:10:38 by mel-mouh #+# #+# */
9-
/* Updated: 2024/11/19 22:00:54 by mel-mouh ### ########.fr */
9+
/* Updated: 2024/11/20 12:21:49 by mel-mouh ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

ft_putnbr.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: mel-mouh <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/11/18 19:09:59 by mel-mouh #+# #+# */
9-
/* Updated: 2024/11/19 22:00:54 by mel-mouh ### ########.fr */
9+
/* Updated: 2024/11/20 12:21:48 by mel-mouh ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

ft_putnbrhex.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: mel-mouh <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/11/18 19:09:24 by mel-mouh #+# #+# */
9-
/* Updated: 2024/11/19 22:15:37 by mel-mouh ### ########.fr */
9+
/* Updated: 2024/11/20 12:21:45 by mel-mouh ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

ft_putstr.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: mel-mouh <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2024/11/18 19:08:39 by mel-mouh #+# #+# */
9-
/* Updated: 2024/11/19 22:04:39 by mel-mouh ### ########.fr */
9+
/* Updated: 2024/11/20 12:21:43 by mel-mouh ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

libftprintf.a

15.1 KB
Binary file not shown.

main.c

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <unistd.h>
2+
#include <stdio.h>
3+
#include <fcntl.h>
4+
#include <stdlib.h>
5+
#include "ft_printf.h"
6+
7+
int main(void)
8+
{
9+
// Close the standard output (stdout)
10+
fclose(stdout);
11+
12+
// Redirect stderr to a file to verify error handling
13+
int error_fd = open("errors.log", O_WRONLY | O_CREAT | O_TRUNC, 0644);
14+
if (error_fd == -1)
15+
{
16+
perror("Failed to open errors.log");
17+
return (1);
18+
}
19+
if (dup2(error_fd, STDERR_FILENO) == -1)
20+
{
21+
perror("Failed to redirect stderr");
22+
close(error_fd);
23+
return (1);
24+
}
25+
26+
// Test ft_printf with stdout closed
27+
int ret = ft_printf("Testing %s with closed stdout\n", "output");
28+
29+
// Check the return value of ft_printf
30+
if (ret == -1)
31+
dprintf(STDERR_FILENO, "ft_printf returned -1: Output is closed\n");
32+
33+
// Clean up
34+
close(error_fd);
35+
36+
// Inform user about the results
37+
printf("Check the errors.log file for the output.\n");
38+
return (0);
39+
}

0 commit comments

Comments
 (0)