common.c 1.4 KB

123456789101112131415161718192021222324252627282930313233
  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. /* {{{ */
  14. void xls_file_path(zend_string *file_name, zval *dir_path, zval *file_path)
  15. {
  16. zend_string *full_path, *zstr_path;
  17. zstr_path = zval_get_string(dir_path);
  18. if (Z_STRVAL_P(dir_path)[Z_STRLEN_P(dir_path)-1] == '/') {
  19. full_path = zend_string_extend(zstr_path, ZSTR_LEN(zstr_path) + ZSTR_LEN(file_name), 0);
  20. memcpy(ZSTR_VAL(full_path)+ZSTR_LEN(zstr_path), ZSTR_VAL(file_name), ZSTR_LEN(file_name)+1);
  21. } else {
  22. full_path = zend_string_extend(zstr_path, ZSTR_LEN(zstr_path) + ZSTR_LEN(file_name) + 1, 0);
  23. ZSTR_VAL(full_path)[ZSTR_LEN(zstr_path)] ='/';
  24. memcpy(ZSTR_VAL(full_path)+ZSTR_LEN(zstr_path)+1, ZSTR_VAL(file_name), ZSTR_LEN(file_name)+1);
  25. }
  26. ZVAL_STR(file_path, full_path);
  27. }
  28. /* }}} */