Re: [PATCH] Repalce strncmp by memcmp

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Pavel Vasilyev
Date: Sunday, November 28, 2010 - 8:11 pm

On 29.11.2010 05:29, Ming Lei wrote:
#include <stdio.h>
#include <errno.h>

int main() {

   char *STR = "XXXX\0";
   char *XXX = "XXXX";
   int a, b;

     errno = 0; a = memcmp(STR, XXX, 5);  a += errno;
     errno = 0; b = strncmp(STR, XXX, 5); b += errno;
     printf("5 chars: %d %d \n", a, b);
     errno = 0; a = memcmp(STR, XXX, 4);  a += errno;
     errno = 0; b = strncmp(STR, XXX, 4); b += errno;
     printf("4 chars: %d %d \n", a, b);

     printf("SWAP STRINGS\n");

     errno = 0; a = memcmp(XXX, STR, 5);  a += errno;
     errno = 0; b = strncmp(XXX, STR, 5); b += errno;
     printf("5 chars: %d %d \n", a, b);
     errno = 0; a = memcmp(XXX, STR, 4);  a += errno;
     errno = 0; b = strncmp(XXX, STR, 4); b += errno;
     printf("4 chars: %d %d \n", a, b);

return 0;
}
----
# ./a.out
5 chars: 0 0
4 chars: 0 0
SWAP STRINGS
5 chars: 0 0
4 chars: 0 0

But I think the same thing  ;)

-- 

                                                         Pavel.

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] Repalce strncmp by memcmp, Pavel Vasilyev, (Sun Nov 28, 7:09 pm)
Re: [PATCH] Repalce strncmp by memcmp, microcai, (Sun Nov 28, 7:21 pm)
Re: [PATCH] Repalce strncmp by memcmp, Ming Lei, (Sun Nov 28, 7:29 pm)
Re: [PATCH] Repalce strncmp by memcmp, Américo Wang, (Sun Nov 28, 8:10 pm)
Re: [PATCH] Repalce strncmp by memcmp, Pavel Vasilyev, (Sun Nov 28, 8:11 pm)
Re: [PATCH] Repalce strncmp by memcmp, Dmitry Torokhov, (Sun Nov 28, 9:13 pm)
Re: [PATCH] Repalce strncmp by memcmp, YOSHIFUJI Hideaki, (Sun Nov 28, 10:26 pm)
Re: [PATCH] Repalce strncmp by memcmp, Andi Kleen, (Mon Nov 29, 3:18 am)
Re: [PATCH] Repalce strncmp by memcmp, Pavel Vasilyev, (Mon Nov 29, 5:41 am)
Re: [PATCH] Repalce strncmp by memcmp, Steven Rostedt, (Mon Nov 29, 7:58 am)
Re: [PATCH] Repalce strncmp by memcmp, Pavel Vasilyev, (Mon Nov 29, 12:41 pm)
Re: [PATCH] Repalce strncmp by memcmp, Steven Rostedt, (Mon Nov 29, 3:18 pm)
Re: [PATCH] Repalce strncmp by memcmp, Steven Rostedt, (Mon Nov 29, 3:26 pm)
Re: [PATCH] Repalce strncmp by memcmp, Pavel Vasilyev, (Mon Nov 29, 3:49 pm)
Re: [PATCH] Repalce strncmp by memcmp, Ryan Mallon, (Mon Nov 29, 3:51 pm)
Re: [PATCH] Repalce strncmp by memcmp, Arnaud Lacombe, (Mon Nov 29, 4:32 pm)
Re: [PATCH] Repalce strncmp by memcmp, Américo Wang, (Tue Nov 30, 2:24 am)
Re: [PATCH] Repalce strncmp by memcmp, Bernd Petrovitsch, (Tue Nov 30, 3:27 am)
Re: [PATCH] Repalce strncmp by memcmp, Bernd Petrovitsch, (Tue Nov 30, 3:34 am)