common.c 1.4 KB

12345678910111213141516171819202122232425262728293031
  1. /*
  2. +----------------------------------------------------------------------+
  3. | XlsWriter Extension |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 2017-2018 The Viest |
  6. +----------------------------------------------------------------------+
  7. | http://www.viest.me |
  8. +----------------------------------------------------------------------+
  9. | Author: viest <[email protected]> |
  10. +----------------------------------------------------------------------+
  11. */
  12. #include "xlswriter.h"
  13. void xls_file_path(zend_string *file_name, zval *dir_path, zval *file_path)
  14. {
  15. zend_string *full_path, *zstr_path;
  16. zstr_path = zval_get_string(dir_path);
  17. if (Z_STRVAL_P(dir_path)[Z_STRLEN_P(dir_path)-1] == '/') {
  18. full_path = zend_string_extend(zstr_path, ZSTR_LEN(zstr_path) + ZSTR_LEN(file_name), 0);
  19. memcpy(ZSTR_VAL(full_path)+ZSTR_LEN(zstr_path), ZSTR_VAL(file_name), ZSTR_LEN(file_name)+1);
  20. } else {
  21. full_path = zend_string_extend(zstr_path, ZSTR_LEN(zstr_path) + ZSTR_LEN(file_name) + 1, 0);
  22. ZSTR_VAL(full_path)[ZSTR_LEN(zstr_path)] ='/';
  23. memcpy(ZSTR_VAL(full_path)+ZSTR_LEN(zstr_path)+1, ZSTR_VAL(file_name), ZSTR_LEN(file_name)+1);
  24. }
  25. ZVAL_STR(file_path, full_path);
  26. }