> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/man/string/bcmp.3.md).

# bcmp.3

`bcmp` — 比较字节字符串

## 名称

`bcmp`

## 库

Lb libc

## 概要

`#include <strings.h>`

`Ft int Fn bcmp const void *b1 const void *b2 size_t len`

## 描述

`bcmp` 函数将字节字符串 `b1` 与字节字符串 `b2` 进行比较，若两者相同则返回零，否则返回非零值。两个字符串均假定为 `len` 字节长。零长度字符串总是相同的。

两个字符串可以重叠。

## 参见

[memcmp(3)](/man/string/memcmp.3.md), strcasecmp(3), [strcmp(3)](/man/string/strcmp.3.md), [strcoll(3)](/man/string/strcoll.3.md), [strxfrm(3)](/man/string/strxfrm.3.md), timingsafe\_bcmp(3)

## 历史

`bcmp` 函数首次出现于 4.2BSD。其原型此前位于

`#include <string.h>`

之后为遵循 IEEE Std 1003.1-2001 ("POSIX.1") 而移至

`#include <strings.h>`

IEEE Std 1003.1-2008 ("POSIX.1") 移除了 `bcmp` 的规范，且在 IEEE Std 1003.1-2004 ("POSIX.1") 中被标记为 LEGACY。为与其他系统兼容，新程序应使用 [memcmp(3)](/man/string/memcmp.3.md)。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/man/string/bcmp.3.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
