Я пытаюсь получить буфер от пользователя, и когда буфер равен 00 B или 00 W, он переходит в оператор if, но по какой-то причине буфер оказывается больше 0. Я распечатал, какой буфер и это 00 B или 00 W при запросе. Почему это?? Я сравниваю не то?
ssize_t chess_write(struct file *pfile, const char __user *buffer, size_t length, loff_t *offset)
{
int black;
int white;
sprintf(msg, "%s(%zu letters)", buffer, length);
msg_size = strlen(msg);
LOG_INFO("In function %s\n", __FUNCTION__);
LOG_INFO("buffer test in write %s", buffer);
black = strcmp(buffer, "00 B");
white = strcmp(buffer, "00 W");
if (black == 0)
{
LOG_INFO("Chess: Initiate chess as black pieces\n");
}
else if (black < 0)
{
LOG_INFO("Chess: black is less than 0\n");
}
else if (black > 0)
{
LOG_INFO("Chess: black is greater than 0\n");
}
else if (white == 0)
{
LOG_INFO("Chess: Initiate chess as white pieces\n");
}
LOG_INFO("Chess: Wrote %zu characters from the user\n", length);
return length; // return bytes wrote
}
Результат, который я получаю, это
[Apr29 18:58] [chess] Module Started
[ +0.000005] [chess] Device class resgistered correctly
[ +0.000077] [chess] Device created correctly
[ +3.632050] [chess] In function chess_open
[ +0.000706] [chess] In function chess_write
[Apr29 19:00] [chess] In function chess_write
[ +0.000003] [chess] buffer test in write 00 B
[ +0.000001] [chess] Chess: black is greater than 0
[ +0.000001] [chess] Chess: Wrote 5 characters from the user
[ +0.001368] [chess] In function chess_read
[ +0.000002] [chess] buffer test in read 00 B
(5 letters)
[ +0.000001] [chess] Chess: black is greater than 0
[ +0.000002] [chess] Chess: Read 16 characters to the user
[ +0.002089] [chess] In function chess_write
[ +0.000002] [chess] buffer test in write 01
[ +0.000000] [chess] Chess: black is greater than 0
[ +0.000001] [chess] Chess: Wrote 3 characters from the user
[ +0.007073] [chess] In function chess_read
[ +0.000001] [chess] buffer test in read 01
(3 letters)
[ +0.000001] [chess] Chess: black is greater than 0
[ +0.000001] [chess] Chess: Read 14 characters to the user
Ps. Я работаю с LOG_INFO в другом файле
#define _CONFIG_PRINTK(once, level, fmt, ...) \
do{ \
printk##once(KERN_##level "[" MODULE_NAME "] " fmt, \
##__VA_ARGS__); \
} while(0)
#define LOG_INFO(format, ...) _CONFIG_PRINTK(, INFO, format, ##__VA_ARGS__)
#define LOG_WARNING(format, ...) _CONFIG_PRINTK(, WARNING, format, ##__VA_ARGS__)
#define LOG_ERROR(format, ...) _CONFIG_PRINTK(, ERR, format, ##__VA_ARGS__)