问题的处理路径长度 [英] Problem with handling path length

查看:110
本文介绍了问题的处理路径长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建库,将用于文件操作,无论是在Linux和Windows。所以,我需要处理的路径,主要的要求就是我的功能将在收到UTF8格式字符串。但它会导致一些问题,其中之一是我使用 MAX_PATH 在Windows和 PATH_MAX 在Linux中,重新present静态路径变量。在ASCII字符的情况下不会有问题,但是当路径包含单code字符,如果UNI code字符需要每个字符2个字节,3次短,如果路径的长度将是两次短单code char字符需要每个字符3字节等。那么,有没有这个问题很好的解决方案?

I'm creating library which will be used for file manipulations, both on linux and windows. So I need to handle paths, the main requirements is that my functions will recieve strings in UTF8 format. But it causes some problems, one of them is I'm using MAX_PATH on windows and PATH_MAX in linux, to represent static path variables. In the case of ASCII characters there will be no problem, but when path contains unicode characters, the length of path will be twice shorter if unicode char requires 2 bytes per char, 3 times shorter if unicode char requires 3 bytes per char and so on. So is there good solution for this problem?

在此先感谢!

P.S。对不起,我的英语水平。

p.s. sorry for my english.

推荐答案

至少在Linux上,你的担心似乎放错了地方。 Linux(和POSIX一般)治疗路径,终止字节的不透明的blob由\\ 0。它不与字节如何转换为字符关注自身。也就是说,PATH_MAX指定路径名的最大字节长度,而不是字符。

At least on Linux, your concern seems misplaced. Linux (and POSIX in general) treats paths as an opaque blob of bytes terminated by "\0". It does not concern itself with how those bytes are translated to characters. That is, PATH_MAX specifies the max length of a path name in bytes, not in characters.

因此​​,如果路径名称中包含> = 0多字节UTF-8字符,那么它只是意味着在字符的最大路径长度为< = PATH_MAX

So if the path names contains >= 0 multibyte UTF-8 characters, then it just means that the max path length in characters is <= PATH_MAX.

这篇关于问题的处理路径长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆